Basically, I have the same question as this one, which unfortunately never got a satisfying answer.
I have a User model, and each user can have multiple associated addresses in the Address model (one-to-many relationship). Now, what I would like to accomplish is that from the associated addresses of a particular user, I can designate one address as the billing address. For this I have a boolean column in the address database table called billing_address. I would like to set the billing address in the user form with the help of a radio button, but I get either a situation that I am able to select all addresses, like this:
<%= form_for @user do |f| %>
<%= f.fields_for :addresses do |a| %>
<%= a.radio_button :billing_address, 1 %><%= a.label :billing_address %>
<% end %>
<% end %>
or that I am not able to send the billing_address parameter to the controller correctly, like this:
<%= form_for @user do |f| %>
<%= f.fields_for :addresses do |a| %>
<%= radio_button_tag "user[addresses_attributes][billing_address]", 1 %>
<% end %>
<% end %>
Any help help is appreciated to get me the right syntax. Or maybe this is not the correct approach to what I try to accomplish at all?
Set default value of the
illing_addressfor all as false. Now in the radio button field, for each address field set its own id as the value of the corresponding radio button. Then in controller find the address corresponding to the id you get from form, and then update itsbilling_addressto true.