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

时间:2012-06-04 10:07:52

标签: ruby-on-rails postgresql

在尝试使用我的应用程序查找问题24小时后。我终于找到了问题。

我跑了

rake assets:precompile RAILS_ENV=production

我继续犯这个错误。

/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...]

我的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

7 个答案:

答案 0 :(得分:29)

简单的解决方案是在我的application.rb

中添加一个简单的行
config.assets.initialize_on_precompile = false

一切正常。

答案 1 :(得分:10)

这应该有效:     rake assets:预编译RAILS_ENV =开发

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

答案 2 :(得分: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:

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

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

答案 3 :(得分:1)

对我有用的是:

rake assets:precompile RAILS_ENV=production

通过ssh访问您的服务器并输入该命令,它应该可以解决问题。

答案 4 :(得分:1)

此解决方案停止使用rails 4,这里是更新的:只需传递一个虚拟数据库,如本文所述:

https://iprog.com/posting/2013/07/errors-when-precompiling-assets-in-rails-4-0

命令是: bundle exec rake RAILS_ENV = production DATABASE_URL = postgresql:// user:pass@127.0.0.1/dbname assets:precompile

答案 5 :(得分:1)

确保您在本地production文件中有一些虚拟 config/database.yml条目

production:
  <<: *default
  database: your_local_database_name

我在2016年遇到了与Rails 4.2.6和Capistrano 3.4相同的错误。 我们在部署脚本中预先编译资产,然后将它们与代码一起上传,但是rake资产:预编译需要一些生产条目,即使它只是一个虚拟的。资料来源:https://github.com/TalkingQuickly/capistrano-3-rails-template/issues/12

答案 6 :(得分:-2)

致电rake assets:precompile:all

相关问题