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.

Ability to skip html-escaping in options_for_select()

#709

I need the ability to insert non-breaking spaces ( ) in option tags that are currently being generated with the collection_select helper. However, options_for_select() always html_escapes the text of an option tag (line 201 of rails/actionpack/lib/action_view/helpers/form_options_helper.rb).

It would be wonderful if one could pass an option that tells options_for_select to skip html_escaping of the option text so that we wouldn't have to build option tags by hand when html entities need to be included.

In investigating the issue, I noticed that Kevin Clark submitted a patch for this way back in 2005, but the ticket was closed as "wontfix". Looking at the comments on the ticket (http://dev.rubyonrails.org/ticke..., I think the ticket "wontfix" resolution was more due to misunderstanding rather than it not being a valid issue. Would a patch to the current rails codebase allowing similar flexibility meet the same fate?

Reported by Jonathon Wolfe · July 26th, 2008 @ 01:57 AM

State: wontfix
Milestone: 2.x
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Pratik
    Pratik
    • State changed from new to incomplete

    It sounds like a reasonable thing to me. Please submit a patch.

    July 26th, 2008 @ 03:17 PM

  2. Pratik
    Pratik
    • Assigned user set to Pratik

    July 26th, 2008 @ 03:17 PM

  3. Jonathon Wolfe
    Jonathon Wolfe

    Hey, I forgot about this ticket for a while, sorry.

    I did put together a changeset a while back that adds the ability to skip the html-escaping in options_for_select, but I actually don't think it should be applied -- the patch took more code than I had anticipated, and required changing the call signature of options_for_select, options_from_collection_for_select, and option_groups_from_collection_for_select in order for things to be consistent.

    I'd thought it would be a simple one-line change, and it would have been if these methods took an options hash rather than a host of separate params, but as it is, I think the patch would add more complexity than it's worth, and it's better to say you've got to build your option tags yourself if you want the contents to not be html-escaped.

    October 13th, 2008 @ 07:32 PM

  4. Pratik
    Pratik
    • State changed from incomplete to wontfix

    Ok let's close this for now then.

    October 13th, 2008 @ 10:45 PM