ryanb / nested_form

Rails plugin to conveniently handle multiple models in a single form.
MIT License
1.79k stars 505 forks source link

link_to_add and radio buttons #178

Closed mark100net closed 12 years ago

mark100net commented 12 years ago

I am having a problem in a nested form with radio button fields (the field is a boolean in the collection where only one of the members should be true).

My code to render the radio button inside the nested_form_for is:

     <%= radio_button_tag "correct_distractor", d.object.id, d.object.correct %>

(if I use the usual form_for syntax and call radio_button on the nested_form_for object, the radio button does not behave like a radio button in that checking on does not uncheck the others)

Now usually when the user clicks one of the radio buttons to change the selected item the id of the new item is sent in the params, so it's fine. But...on new items that are added at runtime with link_to_add, there is no id to send, so all that is sent is:

"correct_distractor" => "on"

So can someone explain to me the proper way to implement radio buttons in a nested form when only one element of the collection should have the value turned on?

Thanks

lest commented 12 years ago

Seems it's not an issue. I'd suggest asking such questions on StackOverflow. Thanks!