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

后端 未结 3 1119
难免孤独
难免孤独 2021-01-14 03:21

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

相关标签:
3条回答
  • 2021-01-14 03:53

    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"

    0 讨论(0)
  • 2021-01-14 03:57

    For Rails 3.2 add this under config/initializers

    module ActionView::Helpers::AssetTagHelper
    
      def image_alt(src)
        return ''
      end
    
    end
    
    0 讨论(0)
  • 2021-01-14 04:15

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

    def image_alt(src)
      ''
    end
    
    0 讨论(0)
提交回复
热议问题