Rake Assets:Precompile Attempting to Connect to Database

rake assets:precompile attempting to connect to database

rake assets:precompile initializes your app by default, which includes connection to the database.

Inside config/application.rb you can add this, but see the link below for warnings about it:

config.assets.initialize_on_precompile = false

Rails Guide on Precompiling Assets

rake assets:precompile trying to connect to production database?

I had the following line in one of my Rake task files

require File.expand_path(File.join(File.dirname(__FILE__), '../..', 'config', 'environment'))

Removing it solved the problem.

rake assets:precompile doesn't work with PostgreSql

Rake initializes the whole rails stack and the postgres adapter seems to test the connection on startup. Since there are no credentials for that case, rake fails.

To prevent rake from doing so, I had to put that in my config/application.rb:

config.assets.initialize_on_precompile = false

That works for me!

Found in this answer.

bundle exec rake assets:precompile - database configuration does not specify adapter

The simple solution was to add one simple line to my application.rb

config.assets.initialize_on_precompile = false

And everything works.

rake assets:precompile RAILS_ENV=production Error

In local computer you are trying to run

rake assets:precompile RAILS_ENV=production

but this requires your local compute to have config/database.yml with the config mentioned by @thieu-nguyen

so add the following in

username: $PRODUCTION_DB_USER

password: $PRODUCTION_DB_PASS

under production in config/database.yml

then add the environment for you local computer as

PRODUCTION_DB_USER=anzels

PRODUCTION_DB_PASS=1234

and for heroku as

PRODUCTION_DB_USER=user

PRODUCTION_DB_PASS="" (empty)



ANOTHER EASIER WAY IS

username: anzels

password: 1234

to production in config/database.yml **JUST BEFORE assests precompilation **
then run command

git checkout config/database.yml

JUST BEFORE GIT COMMIT command
the idea is to not to commit the username and password but temporarily edit it for assests precompilation purpose only

assets:precompile connects to DB when initialize_on_precompile is false

According to Heroku, this config is only available in Rails 3.x.
You can also see here in rails/rails repo on Rails 4 that the config for assets isn't there anymore:
https://github.com/rails/rails/blob/master/railties/lib/rails/application/configuration.rb

For quick assets compiling, I use a simple sqlite3 config in production. It always connects no matter what. Your database.yml file should not be taken as is from your repo in production anyway. Either you use Heroku or a simple capistrano symlink to your shared folder, or any other custom solution.

How to universally skip database touches when precompiling assets on Heroku

EDIT: This answer is out of date and no longer works - See fringd's answer.

Not quite a universal stubbing but devise has added a check now to fix this particular problem . See the issue and fix on Github. By providing a RAILS_ASSETS_PRECOMPILE environment config devise should skip building the routes



Related Topics



Leave a reply



Submit