How to get correct index and name with fields_for parents[], parent do |f| and f.fields_for :children, child

   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

<%= 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 %>

f.text_field :job correctly generates

<input id="parents_1_job" type="text" value="coding" size="30"

But cf.text_field :chore generates ids and names that don't have the
parent index.


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?