2012-06-04 48 views
9

经过24小时试图找到我的应用程序的问题。我终于找到了问题。bundle exec rake资产:预编译 - 数据库配置没有指定适配器

我跑

rake assets:precompile RAILS_ENV=production 

,我不停地收到这个错误。

/Users/vezu/.rvm/rubies/ruby-1.9.3-p194/bin/ruby /Users/vezu/.rvm/gems/[email protected]/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 
+0

m8哪里是你的生产数据库配置?)) –

+0

你不需要它在Heroku上。 Heroku为你处理。对不起,我忘了提及我使用heroku。 – Benjamin

回答

29

简单的解决方案是一个简单的线条添加到我的application.rb中

config.assets.initialize_on_precompile = false 

和一切正常。

+2

只需要注意:确保你将上面的行添加到你的config/application.rb中。我错误地将它添加到config/environments/production.rb,这将不起作用 – ChrisBurgess

+2

Rails 4.x中的PSA此选项已被删除 – steakchaser

10

这应该工作: 耙资产:预编译RAILS_ENV =发展

它试图加载您的生产环境中,当你的database.yml不包括它。

+0

对于使用Asset Sync的任何人的说明。将RAILS_ENV设置为开发将防止资源同步在编译后同步。 – Undistraction

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任务需要一个变量,所以给它一个虚拟的。

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

+0

值得注意的是,从Rails 4 Heroku开始,现在不再覆盖你的database.yml –

-1

呼叫rake assets:precompile:all

1

什么工作对我来说是这样的:通过ssh和该命令的类型

rake assets:precompile RAILS_ENV=production

访问您的服务器,它应该做的伎俩。

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

相关问题