Ruby on rails bundle exec rake资产:预编译-数据库配置未指定适配器
经过24小时的尝试,我的应用程序出现了问题。我终于找到了问题所在 我跑Ruby on rails bundle exec rake资产:预编译-数据库配置未指定适配器,ruby-on-rails,postgresql,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=
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
简单的解决方案是在我的application.rb中添加一行代码
config.assets.initialize_on_precompile = false
一切正常。这应该可以:
rake资产:预编译RAILS\u ENV=development
当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
# Add the below...
production:
adapter: postgresql
host: localhost
encoding: unicode
database: ndoda_production
pool: 5
username:
password:
Heroku将用自己的版本覆盖您的database.yml,而不管您在其中添加了什么但是,在生产环境中运行的rake任务需要一个变量,所以给它一个虚拟变量
如上所述,您还可以将'config.assets.initialize_on_precompile=false'添加到production.rb中。如果设置,Heroku要求将其设置为“false”。调用rake资产:预编译:all对我有效的是:
rake资产:预编译RAILS\u ENV=production
通过ssh访问您的服务器并键入该命令,它应该可以做到这一点。此解决方案停止使用rails 4,以下是更新的解决方案:只需传递本文中提到的虚拟数据库: 命令是:
bundle exec rake RAILS\u ENV=production DATABASE\u URL=postgresql://user:pass@127.0.0.1/dbname资产:预编译确保在本地
config/database.yml
文件中有一些虚拟生产
条目
production:
<<: *default
database: your_local_database_name
生产:
m8生产数据库配置在哪里?)Heroku上不需要它。Heroku会帮你处理的。抱歉,我忘了提到我使用heroku。请注意:请确保将上面的行添加到config/application.rb。我错误地将它添加到config/environments/production.rb中,这在Rails 4.x中不起作用。此选项已被删除。请注意使用资产同步的任何人。将RAILS_ENV设置为development将阻止编译后同步资产。值得注意的是,从RAILS 4开始,Heroku现在不再覆盖database.yml