I\'m attempting to debug why my application is attempting to connect to my database when I run rake assets:precompile --trace
.
I\'m probably missing so
Maybe this won't work for all cases but I was able to avoid Rails attempting to connect to the database on the rake assets:*
tasks by surrounding the code in some places with the snippet below on the /config/routes.rb
:
unless defined?(::Rake::SprocketsTask)
devise_for ...
#...
end
devise_scope ...
#...
end
end
Sometimes code which depends on external services or environment variables will get loaded because of code on the initializer files which are not required for assets to be precompiled.
I've recently faced a similar issue and the responses above didn't work for me. I've found the file on config/initializers/
that was causing the issue and wrapped it with the following code:
unless defined?(::Rake::SprocketsTask)
#...
end
The snippet above will skip the code within it when running rake assets:precompile
or others like rake assets:clean
as well.
Hopefully this will help others in the future!