image_tag - Is there a way to make the alt attr blank by default?

血红的双手。 提交于 2019-12-01 09:14:29

For Rails 3.2 add this under config/initializers

module ActionView::Helpers::AssetTagHelper

  def image_alt(src)
    return ''
  end

end

You can monkey-patch ActionView::Helper#image_alt with:

def image_alt(src)
  ''
end

Or use your own version of image helper

#ApplicationHelper
def my_image_tag(source, options={})
  options(:alt) = ''
  image_tag(source, options)
end

Then use it, my_image_tag "test/test.png"

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