2012-06-04 49 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

相關問題