Looking at the example of form_for from the rails docs, I see this example:
<%= form_for @person do |person_form| %>
First name: <%= person_form.text_field :first_name %>
Last name : <%= person_form.text_field :last_name %>
<%= fields_for @person.permission do |permission_fields| %>
Admin? : <%= permission_fields.check_box :admin %>
<% end %>
<%= f.submit %>
<% end %>
I tried copying this template, but noticed that in order to get the update to work correctly, I had to change the field_for line to
<%= person_form.fields_for @person.permission do |permission_fields| %>
Any idea why they are showing the fields_for without the parent form variable in front (person_form)?
The examples later in the docs show it with the parent form variable.
Thanks
it is correct with
person_form. think of it as the formtag and you just assign the inputs to the form. all the names of the form get set like this (person[attribute]).fields_forwithoutperson_formwould create other name like (permission[admin]) – this would fail because the permission object is not connected with the person. through theperson_form.fields_forthe names get right (person[permission][admin]). you get the nested attribute without doing anything more.