Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

sending :alt => nil to an image tag should omit the images alt tag

#4558

I have an app where I set the alt tag of images with javascript. To reduce the size of the page, I want to emit img tags with no alt attribute, however that is not currently possible:

image_tag "foo.png", :alt => nil # => <img alt="Foo" src="/images/foo.png" />

I agree that images should have alt tags, and I agree that the default is sensible. However, if I explicitly send :alt => nil, I expect it to omit the alt attribute altogether, to be consistent with :class and other html attributes.

I plan to submit a patch momentarily.

Reported by Jeff Dean · May 9th, 2010 @ 06:08 AM

State: resolved
Milestone: 3.0.2
Assigned to: José Valim José Valim
Importance: none

Activity

  1. Jeff Dean
    Jeff Dean

    Here's a patch that fixes it, with a test.

    May 9th, 2010 @ 06:10 AM

  2. Jeff Dean
    Jeff Dean
    • Tag changed from action_view to action_view, patch

    May 9th, 2010 @ 06:10 AM

  3. Mislav
    Mislav

    +1 for teaching me about Hash#fetch

    May 9th, 2010 @ 03:27 PM

  4. Dan Pickett
    Dan Pickett
    • Tag changed from action_view, patch to action_view, bugmash, patch

    May 9th, 2010 @ 05:51 PM

  5. Anthony Burns
    Anthony Burns

    +1 for teaching me Hash#fetch as well

    May 9th, 2010 @ 06:42 PM

  6. Marc-André Lafortune
    Marc-André Lafortune

    Hi Jeff!

    I'd recommend using the block form of fetch, to avoid an unnecessary calculation in case the :alt option is specified. Modified diff attached.

    May 9th, 2010 @ 09:19 PM

  7. Marc-André Lafortune
    Marc-André Lafortune

    Let's try the attachment again...

    May 9th, 2010 @ 09:19 PM

  8. Jeff Dean
    Jeff Dean
    • Tag cleared.

    And thanks for Marc-Andre for introducing me to fetch last year! I forgot about the block syntax.

    May 10th, 2010 @ 02:36 AM

  9. Josh Kalderimis
  10. José Valim
    José Valim
    • Milestone cleared.
    • Assigned user set to José Valim

    May 10th, 2010 @ 11:12 AM

  11. Tony Pitale
    Tony Pitale

    +1 would be nice, definitely had this minor annoyance.

    May 10th, 2010 @ 05:35 PM

  12. Repository
    Repository
    • State changed from new to resolved

    May 15th, 2010 @ 08:51 AM

  13. Jeremy Kemper
    Jeremy Kemper
    • Tag set to 3, documentation, patch, review
    • Milestone set to 3.0.2

    October 15th, 2010 @ 11:01 PM