Rails会忽略ActionView :: Template :: Error丢失资产 [英] Rails ignore ActionView::Template::Error for missing assets

查看:93
本文介绍了Rails会忽略ActionView :: Template :: Error丢失资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ActionView::Template::Error (leagues/lal11.png isn't precompiled):

添加新联赛但未预编译对应的图像时,在我的应用中会发生此类错误.

我理解为什么会这样;资产清单缺少相关路径,因此Rails无法为其确定摘要.但是,由于缺少简单的映像而杀死整个应用程序是愚蠢的.有没有办法捕获这个特定的异常?

解决方案

我完全同意您的看法,由于缺少图像而引发错误...我认为资产管道是Rails中最糟糕的代码!/p>

我对如何解决该问题有一些想法:

您可以启用实时编译config.assets.compile = true

您可以在使用的助手(image_tag或其他工具)中捕获该错误,并渲染默认图像.

如果错误未遍及您的应用,则可以在控制器中使用rescue_from.

ActionView::Template::Error (leagues/lal11.png isn't precompiled):

Errors of this sort happen in my app when a new league is added but the corresponding image hasn't been precompiled.

I understand why this is happening; the asset manifest is missing the relevant path and so rails can't determine the digest for it. However, killing the whole app because of a simple missing image is stupid. Is there a way to catch this specific exception?

解决方案

i could not agree more with you, raising errors for missing images... i think the asset-pipeline is the most crappy piece of code in rails!

i have some ideas on how you could tackle the problem:

you could enable live compilation config.assets.compile = true

you could catch that error in the helper you are using (image_tag or whatever) and render a default image.

you could use rescue_from in your controller if the error is not allover your app.

这篇关于Rails会忽略ActionView :: Template :: Error丢失资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆