I have the following:
class Title
has_many :roles
has_many :people, :through => :roles
accepts nested_attributes_for :roles
(Roles and People are also correctly defined)
In my title#edit view, I have the fields_for set up correctly and
working:
<%= f.fields_for :roles do |builder| %>
<%= render "role_fields", :f => builder %>
<%- end -%>
and in the role_fields partial, I have
<%= f.check_box :primary %>
<%= f.label :primary %>
Now I would like to change the check_box (which does work correctly)
into a radio button, so only one of the nested roles would be the
primary role. How can I use nested attributes and radio buttons?
If I replace the f.check_box call with f.radio_button( :primary,
true ) I end up with a radio group that acts like a bunch of
individual radio groups -- I can click on any of them and each one
will check on without deselecting any of the others. If I change the
name, so that each button has the same name, then the radio group
works as expected, but the nested form breaks. I need those unique
index names (title[roles_attributes][0][primary],
title[roles_attributes][1][primary], title[roles_attributes][3]
[primary], etc.) to set the primary attribute on the correct nested
role.
Short of using JavaScript to enforce the one-radio-button-at-a-time
rule here, is there any way to do a nested form with radio buttons
like this?
Thanks in advance,
Walter
--
You received this message because you are subscribed to the Google Groups "Ruby on
Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.