Hi,
I’m editing multiple instances of a parent model in an index view
in one form, as in Railscasts #198. Each parent has_many :children and
accepts_nested_attributes_for :children, as in Railscasts #196 and
#197
<%= form_tag %>
<% for parent in @parents %>
<%= fields_for “parents[]”, parent do |f|
<%= f.text_field :job %>
<%= f.fields_for :children do |cf| %>
<% cf.text_field :chore %>
<% end %>
<% end %>
<% end %>
<% end %>
Given parent.id==1
f.text_field :job correctly generates
But cf.text_field :chore generates ids and names that don’t have the
parent index.
id=“parents_children_attributes_0_chore”
name=“parents[children_attributes][0][chore]”
I’ve stared at the tail end of
and tried lots of combos but haven’t found the magic syntax. Do I
need to subclass FormBuilder and teach it what to do somehow, or is
there a way to tell fields_for what it needs?
Thanks