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.

Support for HTML Class String in options_for_select

#429

A problem I came across while trying to add class names for options was that it just couldn't be done cleanly, from what I could see. In the spirit of keeping views clean, this patch adds the ability to specify a third element in the option container to generate a class name. For example (from docs):

options_for_select([["Dollar", "$", "american"], ["Kroner", "DKK", "danish"]])
#=> <option value="$" class="american">Dollar</option>\n<option value="DKK" class="danish">Kroner</option>

Reported by Edd Morgan · June 16th, 2008 @ 03:15 PM

State: wontfix
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Tarmo Tänav
    Tarmo Tänav

    I don't have an opinion on wether this feature is needed but the patch seems to be using tabs for indenting, these should be replaced with spaces.

    June 18th, 2008 @ 04:29 AM

  2. Chris Barnett
    Chris Barnett

    I don't think this is the best way to fix this problem. What happens when you want to specify the 'id', 'lang', 'style', or 'title' attributes?

    Is there a more general solution?

    June 18th, 2008 @ 07:54 AM

  3. Edd Morgan
    Edd Morgan

    I considered just adding support for an array of hashes as the container but it seems that if one wanted to construct an array of hashes for this, they may as well just iterate their own string of option tags. The class attr seemed to be the one that would be used more often.

    What are everyone's thoughts of adding support for a collection of hashes for each option item?

    June 18th, 2008 @ 04:14 PM

  4. Pratik
    Pratik
    • State changed from new to wontfix
    • Tag set to actionpack, helper, patch

    I don't think this functionality belongs in core. You should try to pluginize it and see if it's widely used. Also, you can get opinions of others on core mailing list.

    Thanks!

    August 21st, 2008 @ 12:18 PM