2013-02-16 68 views
0

我試圖升級已經部署到Heroku的應用程序以使用Rails 3.1中的資產管道。我遵循RailsCasts #282中的所有必要步驟,我的應用在本地運行良好。但是,當我推送到Heroku並嘗試訪問根路徑時,我收到的錯誤爲"foobarbaz.png" is not precompiled。如果我從頁面中刪除第一張圖片,則下一張圖片會出現相同的錯誤,以此類推。所有圖像都被推送到Heroku,所以沒有任何情況下試圖引用不在那裏的圖像。升級到Rails 3.1資產管道證明存在問題

我注意到,當我推應用的Heroku,我做了/沒有看到以下的輸出:

-----> Preparing Rails asset pipeline 
     Running: rake assets:precompile 

我試着運行rake assets:precompile本地和不斷收到以下錯誤:

rake aborted! 
production database is not configured 

由於使用Heroku,我的database.yml文件中沒有生產配置。當我嘗試運行heroku run rake assets:precompile,我得到以下錯誤:

rake aborted! 
Application has been already initialized. 

我已經添加了必要的行application.rb中,我的環境文件,我似乎無法得到它的工作!

+0

你有 '''要求「導軌/ all'''''''Bundler.require(* Rails.groups(:資產))?如果定義(捆紮機) '''在你的application.rb中? – phoet 2013-02-16 18:31:52

+0

是的,我嘗試用該行替換我所擁有的代碼(RailsCast中給出的代碼),並且仍然具有相同的錯誤。 – 2013-02-26 11:33:27

回答

1

如果存在manifest.yml文件,Heroku假定您正在做自己的預編譯(您遇到問題)。

從您的公共或公共/資產文件夾中移除manifest.yml。

將更改推送到heroku。下面的例子。

$ git rm public/assets/manifest.yml 
$ git commit -m "remove precompile manifest" 
$ git push -f heroku master 

運行資產:預編譯在heroku服務器上。輸入:

$ heroku run rake assets:precompile 
+0

我的項目中沒有任何manifest.yml文件。 – 2013-02-25 23:19:59

+0

你的database.yml文件是什麼? – 2013-02-26 09:11:59

+0

開發和測試數據庫的配置選項。我沒有生產配置,因爲我使用Heroku。 – 2013-02-26 11:30:13

2

這個問題發生在我身上的歡迎,並在我的情況,那是因爲我對我的config/application.rb中

config.assets.initialize_on_precompile以下行=假

它似乎根據的Heroku(https://devcenter.heroku.com/articles/rails-asset-pipeline)需要在Rails中的某些版本中,

While precompiling assets, in Rails 3.x, you can prevent initializing your application and connecting to the database by ensuring that the following line is in your config/application.rb:

config.assets.initialize_on_precompile = false

但對我來說它已經扔「在應用itialized'異常,並且在我移除它之後就消失了

由於Heroku日誌在部署時並不真正有用,我測試它的方式是在我的heroku實例上運行資源預編譯rake任務:

Heroku的運行耙資產:預編譯