2012-05-29 63 views
7

我知道Heroku的運行耙資產:預編譯任務:的Heroku /的Ruby-on-Rails的錯誤:圖像不預編譯

-----> Writing config/database.yml to read from DATABASE_URL 
-----> Preparing app for Rails asset pipeline 
     Running: rake assets:precompile 
-----> Rails plugin injection 
     Injecting rails_log_stdout 
     Injecting rails3_serve_static_assets 
-----> Discovering process types 
     Procfile declares types  -> (none) 
     Default types for Ruby/Rails -> console, rake, web, worker 
-----> Compiled slug size is 17.7MB 
-----> Launching... done 

我告訴它production.rb預編譯的圖像

# from: http://stackoverflow.com/questions/8052865/rails-3-1-asset-pipeline-why-my-images-do-not-precompile-for-production 
config.assets.precompile += %w[*.png *.jpg *.jpeg *.gif] 

那麼,爲什麼我仍然得到這個500錯誤?

2012-05-29T02:57:15+00:00 app[web.1]: Started GET "/signin" for 46.114.68.16 at 2012-05-29 02:57:15 +0000 
2012-05-29T02:57:15+00:00 app[web.1]: Processing by SessionsController#new as HTML 
2012-05-29T02:57:15+00:00 app[web.1]: Rendered sessions/new.html.erb within layouts/application (25.4ms) 
2012-05-29T02:57:15+00:00 app[web.1]: Completed 500 Internal Server Error in 27ms 
2012-05-29T02:57:15+00:00 app[web.1]: 
2012-05-29T02:57:15+00:00 app[web.1]: ActionView::Template::Error (twitter_64.png isn't precompiled): 
2012-05-29T02:57:15+00:00 app[web.1]:  25: <div id="auths"> 
2012-05-29T02:57:15+00:00 app[web.1]:  27: <a href="/auth/twitter" class="provider"> 
2012-05-29T02:57:15+00:00 app[web.1]:  26: <h2>Or sign in through one of these:</h2> 
2012-05-29T02:57:15+00:00 app[web.1]:  28:  <%= image_tag "twitter_64.png", :size => "64x64", :alt => "Twitter" %>Twitter</a> 

有趣的是,我在其他頁面上顯示的圖像很好。不知道爲什麼有些圖片是行不通的,但有些人會...

+0

你確定'twitter_64.png'在資產目錄('app/assets/images','lib/assets/..'或'vendor/assets..')嗎? – luacassus

+0

爲什麼你想要預編譯圖像? – ksol

回答

7

首先,要確保你有這一套,以及:

config.assets.initialize_on_precompile = false 

如果不工作,這是值得一試在構建slug之前手動運行預編譯任務;我認爲有這樣做的方式,當細微的差別:

RAILS_ENV=production bundle exec rake assets:precompile 

最後,它不是一個解決方案,但如果一切都失敗,暫時的解決辦法是設置

config.assets.compile = true 
+0

感謝這個,在我推送之前運行'RAILS_ENV =生產包exec rake assets:precompile'。 – Jason

1

確保你是把您在

app/assets/images 

圖像不

public/assets 

直接。

然後運行rake assets:precompile看看它是否有所改善。它可能會讓人有點困惑。

+0

這會將圖像複製到公共目錄中。一旦將它們添加到公共目錄後,您是否將圖像從app/assets/images目錄中刪除?如何參考文件也有問題。我應該使用他們的普通名稱還是stars-xxxx.jpg名稱。 – flobacca

+1

1)你不必使用他們從Rails系統得到的奇怪名字,只是他們的普通名字。如果他們在一個子文件夾中,只要給他們的相對路徑,否則不是。它知道該怎麼做。 2)不,請不要刪除複製後的app/assets/images目錄。 – mjnissim