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.

f.radio_button ignores parent fields_for's :index option

#1993

The following view code does not work as expected:

fields_for @post, :index => 1 do |f|
  f.radio_button :title, "Hello"
end

The ID of the radio button generated was not post_1_title_hello, instead was post_title_hello. This is because the logic for generating radio button IDs does not rely on the logic for generating the rest of the IDs. It instead completely replaces it.

In my patch, I generate IDs for radio_buttons similarly to everything else and then add on the _value part of the ID (unless override by the user).

Reported by David Stevenson · February 16th, 2009 @ 09:30 PM

State: resolved
Milestone: 2.x
Assigned to: Michael Koziarski Michael Koziarski
Importance: none

Activity

  1. Zach Brock
    Zach Brock
    • Tag changed from fields_for, form_for, form_helper, index, radio_button to fields_for, form_for, form_helper, index, patch, radio_button

    +1

    February 17th, 2009 @ 05:59 PM

  2. Joseph Palermo
  3. Matthew O'Connor
  4. Michael Koziarski
    Michael Koziarski
    • Assigned user set to Michael Koziarski

    This looks good to me, can you combine it with #1992 f.label should work for targeting f.radio_button and upload it here.

    I realise they're different reports, but the patches clash with one another, so best to just do it in one git apply :)

    March 2nd, 2009 @ 05:43 AM

  5. David Stevenson
    David Stevenson
    • Tag set to form_helper, label_tag, patch, radio_button_tag

    Koz,

    Attached patch should fix both issues... and complete with tests.

    March 11th, 2009 @ 04:32 PM

  6. José Valim
  7. Michael Koziarski
    Michael Koziarski
    • State changed from new to resolved

    June 9th, 2009 @ 09:30 AM

  8. bingbing