ActionView::Template::Error(未预编译):

20
在生产环境(Heroku)中,我遇到了以下错误:
Started GET "/articles/1" for 50.134.181.231 at 2012-06-17 00:37:35 +0000
2012-06-17T00:37:35+00:00 app[web.1]: ActionView::Template::Error ( isn't precompiled):
2012-06-17T00:37:35+00:00 heroku[router]: GET wandr.com/articles/1 dyno=web.1 queue=0 wait=0ms service=497ms status=500 bytes=728
2012-06-17T00:37:35+00:00 app[web.1]: 
2012-06-17T00:37:35+00:00 app[web.1]:     74:   = image_tag @article.featured_photo_url(:sm).to_s
2012-06-17T00:37:35+00:00 app[web.1]:     75: 
2012-06-17T00:37:35+00:00 app[web.1]:     77:   = image_tag @article.background_photo_url(:md).to_s
2012-06-17T00:37:35+00:00 app[web.1]:     76: %p
2012-06-17T00:37:35+00:00 app[web.1]:     78: %p
2012-06-17T00:37:35+00:00 app[web.1]:     79:   = image_tag @article.cover_photo_url(:md).to_s
2012-06-17T00:37:35+00:00 app[web.1]:     80: 
2012-06-17T00:37:35+00:00 app[web.1]:   app/views/articles/show.html.haml:77:in `_app_views_articles_show_html_haml__1847247375488199378_48105500'
2012-06-17T00:37:35+00:00 app[web.1]: 
2012-06-17T00:37:35+00:00 app[web.1]:   app/controllers/articles_controller.rb:21:in `show'
2012-06-17T00:37:35+00:00 app[web.1]: 
2012-06-17T00:37:35+00:00 app[web.1]: Processing by ArticlesController#show as HTML
2012-06-17T00:37:35+00:00 app[web.1]:   Rendered articles/show.html.haml within layouts/admin (420.5ms)
2012-06-17T00:37:35+00:00 app[web.1]:   Parameters: {"id"=>"1"}
2012-06-17T00:37:35+00:00 app[web.1]: Completed 500 Internal Server Error in 486ms

我运行的是Rails 3.2.6,其中包括了actionpack 3.2.6,我认为这个问题已经得到了解决:https://github.com/rails/rails/commit/6bb86e1f3f7f9e11ee1c056d8742125173ecbce1 我也尝试过这个方法:"ActionView::Template::Error ( isn't precompiled)" raised on "image_tag nil" 基本上,只要此页面中的任何一个图像不存在,它就会抛出此错误。如果我上传这些图像,它就能正常工作。有什么想法吗?
谢谢, --Mark

似乎这个修复只处理了 "" 而不是 nil - lulalala
1个回答

46

我假设您正在使用像CarrierWave这样的工具来处理文件上传?在您的上传器类中,您可以指定一个默认的图像处理程序:

https://github.com/jnicklas/carrierwave#providing-a-default-url

class MyUploader < CarrierWave::Uploader::Base
  def default_url
    "/images/fallback/" + [version_name, "default.png"].compact.join('_')
  end
end

这将输出默认图像,而不是尝试在资源管道中访问一个不存在的名为 "" 的文件。


它解决了显示问题,但由于策略密钥被默认URL覆盖并被Amazon S3拒绝,因此破坏了carrierwave_direct表单。因此,我没有提供默认URL,而是在显示图像之前先检查其是否存在于视图中。 - Homan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接