“ActionView::Template::Error ( isn't precompiled)” raised on “image_tag nil”

萝らか妹 提交于 2019-11-30 18:57:50

image_tag must have a source, Rails can do nothing with it, but raise an exception.

You can write a helper like this:

module ApplicationHelper
  def safe_image_tag(source, options = {})
    source ||= "default.jpg"
    image_tag(source, options)
  end
end

or simply check for nil directly in a view. Anyway you have to do something to prevent an error.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!