bundle exec rake assets:precompile - 数据库配置没有指定适配器

Ben*_*min 9 postgresql ruby-on-rails

24小时后,我试图找到我的应用程序的问题.我终于找到了问题.

我跑了

rake assets:precompile RAILS_ENV=production
Run Code Online (Sandbox Code Playgroud)

我一直在收到这个错误.

/Users/vezu/.rvm/rubies/ruby-1.9.3-p194/bin/ruby /Users/vezu/.rvm/gems/ruby-1.9.3-p194@global/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
database configuration does not specify adapter

Tasks: TOP => environment
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/Users/vezu/.rvm/rubies/ruby-1.9.3-p194/bi...]
Run Code Online (Sandbox Code Playgroud)

我的database.yml文件看起来像这样

development:
  adapter: postgresql
  host: localhost
  encoding: unicode
  database: ndoda_development
  pool: 5
  username:
  password:

test:
  adapter: postgresql
  encoding: unicode
  database: ndoda_test
  pool: 5
Run Code Online (Sandbox Code Playgroud)

Ben*_*min 29

简单的解决方案是在我的application.rb中添加一个简单的行

config.assets.initialize_on_precompile = false
Run Code Online (Sandbox Code Playgroud)

一切正常.

  • 在Rails 4.x中的PSA此选项已被删除 (3认同)
  • 请注意:确保将以上行添加到config/application.rb中.我错误地将它添加到config/environments/production.rb中,这将无法正常工作 (2认同)

Duk*_*uke 10

这应该工作:rake资产:预编译RAILS_ENV =开发

当您的database.yml不包含它时,它会尝试加载您的生产环境.


Leo*_*Ajc 7

做这个:

development:
  adapter: postgresql
  host: localhost
  encoding: unicode
  database: ndoda_development
  pool: 5
  username:
  password:

test:
  adapter: postgresql
  encoding: unicode
  database: ndoda_test
  pool: 5

# Add the below...

production:
  adapter: postgresql
  host: localhost
  encoding: unicode
  database: ndoda_production
  pool: 5
  username:
  password:
Run Code Online (Sandbox Code Playgroud)

Heroku将使用自己的版本覆盖您的database.yml,无论您放在那里.但是,在生产环境中运行的rake任务需要一个变量,因此请给它一个虚拟变量.

如上所述,您还可以将"config.assets.initialize_on_precompile = false"添加到production.rb.如果设置,Heroku要求将其设置为"false".