Question

I rather have a blank alt attribute if an image is missing instead of the filename of the image (who ever wants this default behavior anyway?)

Is there a way to make a system configuration so image_tag sets a blank alt attr if no alt was given?

Just to be clear: I am not interested in image_tag('path/to/image', :alt => '') I am interested in setting it once for all the image_tags.

Was it helpful?

Solution

For Rails 3.2 add this under config/initializers

module ActionView::Helpers::AssetTagHelper

  def image_alt(src)
    return ''
  end

end

OTHER TIPS

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"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top