2012-05-29 62 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