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.

Allow strings to be sent as collection to select

#2391

Why?

The main reason is to allow the following:


fields_for @post do |f|
  f.select(:category_id, grouped_options_for_select(...))
end

Since grouped_options_for_select returns a string, prior to this patch this wouldn't work. We would have to use select_tag method, which is not very friendly since it does not generate names properly and does not work with nested attributes as well (it wouldn't generate blog[post][0][category], unless explicitly given).

Reported by José Valim · April 1st, 2009 @ 11:55 AM

State: committed
Milestone: 2.x
Assigned to: Eloy Duran Eloy Duran
Importance: none

Activity

  1. Michael Koziarski
    Michael Koziarski
    • Assigned user set to Eloy Duran

    Does this look ok to you eloy?

    Is there more we could do to make the nested form helpers work nicely with select and collection_select?

    April 5th, 2009 @ 10:09 AM

  2. Eloy Duran
    Eloy Duran
    • State changed from new to verified

    The patch does what the ticket says. +1

    If there's more that could be done or isn't working please report. Otherwise I'll inspect this the next time I have to work in this area.

    April 7th, 2009 @ 10:00 PM

  3. José Valim
    José Valim

    Thanks Eloy! You would like to check #2392 to_radio_button_tag ignores :index options partially as well, it's related with the :index option.

    April 7th, 2009 @ 10:18 PM

  4. Matt Jones
    Matt Jones

    You might also want to take a look at #1986 Create optgroups in options_for_select, which allows options_for_select (used by select) to handle optgroups as well.

    May 14th, 2009 @ 08:17 PM

  5. Repository
    Repository
    • State changed from verified to committed

    May 15th, 2009 @ 04:31 AM