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 of html Attributes for options_for_select

#2165

Regarding: ActionView::Helpers::FormOptionsHelper options_for_select

The options_for_select FormOptionsHelper method could easily support html attributes, however it currently ignores them. I recommend supporting html attributes when calling the function with an Array containing name, value & hash of attributes.

I used the attached modification to support this feature... they are not designed to be run by themselves but to be added to form_options_helper.rb

The attached file also contains new tests to ensure proper operation of the method.

Reported by Joshaven Potter · March 7th, 2009 @ 07:15 PM

State: resolved
Milestone: 3.x
Assigned to: José Valim José Valim
Importance: none

Activity

  1. Steve St. Martin
    Steve St. Martin
    • Assigned user set to Ryan Bigg

    Verified on 2.3.5, Please submit a valid patch http://guides.rails.info/contributing_to_rails.html#create-a-patch.

    Can be marked as incomplete.

    April 15th, 2010 @ 09:29 PM

  2. Ryan Bigg
    Ryan Bigg
    • State changed from new to incomplete

    Seems like a great patch. Please format this patch in the suggested way.

    April 15th, 2010 @ 10:40 PM

  3. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  4. Marc Lainez
    Marc Lainez
    • Tag changed from action_view, feature, feature_request, form_options_helper to action_view, feature, feature_request, form_options_helper, patch

    Useful indeed Joshaven, I made a patch including your changes and tests. Tell me if it needs to be reworked.

    May 6th, 2010 @ 01:37 PM

  5. Joshaven Potter
    Joshaven Potter

    Sorry, I have not been working with Rails much for the last few months. I am happy that you guys are taking this and running with it!

    May 6th, 2010 @ 02:48 PM

  6. Dan Pickett
    Dan Pickett
    • Tag changed from action_view, feature, feature_request, form_options_helper, patch to action_view, bugmash, feature, feature_request, form_options_helper, patch

    Marc, was the patch you supplied made against master or 2-3-stable?

    Can bugmashers apply this and check if it cleanly applies to master?

    May 9th, 2010 @ 06:13 PM

  7. Marc Lainez
    Marc Lainez

    It was made against the master branch.

    May 10th, 2010 @ 11:10 AM

  8. Jared Pace
    Jared Pace

    We verified this patch against master, and noticed there were no docs added. So we added some documentation and have attached a revised patch.

    One note of feedback: the method html_attributes_from is pretty complicated, and we thought it should be simplified if at all possible. Also the fact that Marc's original code added three NOTEs smells a little bad to us, maybe that could be cleaned up with explaining methods?

    • Rob and Jared @ Relevance

    May 14th, 2010 @ 03:41 PM

  9. Santiago Pastorino
    Santiago Pastorino
    • State changed from incomplete to open
    • Assigned user changed from Ryan Bigg to José Valim

    Tickets should be new or open if they are being discussed

    May 15th, 2010 @ 12:33 AM

  10. José Valim
    José Valim

    @Jared, I agree. The code can be improved and the to_a call should also be removed (use Array.wrap instead). Anyone willing to improve it, can consider that Jared's patch above will be applied and you can apply your fixes on top of it.

    May 15th, 2010 @ 07:53 AM

  11. pleax
    pleax

    I’ve attached a patch with few more test-cases and slightly different approach to implementation.

    May 15th, 2010 @ 01:44 PM

  12. PacoGuzman
    PacoGuzman

    +1

    All test pass, enough test cases and clean implementation

    May 15th, 2010 @ 04:07 PM

  13. Anil Wadghule
    Anil Wadghule

    +1 Patch applies cleanly. Tests pass. It is an useful feature to have.

    May 15th, 2010 @ 04:32 PM

  14. jslag
    jslag

    Paco and Anil, which patch are you referring to? pleax's?

    May 15th, 2010 @ 05:35 PM

  15. jslag
    jslag

    +1 to pleax's 2165-html_attributes_in_options_for_select.diff

    • verified that it still applies cleanly to master
    • function name 'option_html_attributes' is more internally consistent
    • patching option_text_and_value to handle the potential addition of Hashes is cleaner than the original patch's changes in options_for_select

    May 15th, 2010 @ 08:43 PM

  16. Neil Cook
    Neil Cook

    +1 Patch 2165-html_attributes_in_options_for_select.diff from pleax applies cleanly. Tests pass.

    May 15th, 2010 @ 09:05 PM

  17. Enrico Bianco
    Enrico Bianco

    +1, applies cleanly to current master, tests pass, comprehensive tests and documentation.

    May 15th, 2010 @ 10:59 PM

  18. Repository
  19. José Valim
    José Valim
    • State changed from open to resolved

    May 16th, 2010 @ 01:35 PM

  20. af001
    af001

    私の中で、総合評価のとっても低いアバアバクロホリスタークロ銀座店。アバクロは大好きなんですけどね。一昨日の東京駅付近での打ち合わせの後、散歩がてら久々に行ってきました。そしたらビックリ!相変わらアバクロず、踊っているだけの店員さんとかもいましたが、

    May 5th, 2011 @ 02:55 AM