title: No numeric index needed when saving nested attributes of a resource?
body: <p>I have a Parent model, and a Child model. I'm trying to make a form for creating a Parent and its associated Children at the same time.</p>
  
  <p>In my form, I have a button to "add" a new Child (a Parent can have as many Children as the user defines). When the button is clicked, it adds a hidden field for a Child to the form and sets its Name attribute to some default which will be saved when the form is eventually submitted. I've been doing this by adding a <code>hidden_field_tag</code> to the form on the button click event:</p>
  
  <pre><code>hidden_field_tag "parent[children_attributes][][name]", "something"
  </code></pre>
  
  <p>Which creates:</p>
  
  <pre><code>&lt;input id="children_attributes__name" name="parent[children_attributes][][name]" type="hidden" value="something"&gt;
  </code></pre>
  
  <p>This seems to work! But I am concerned for the empty <code>[]</code>. I'm not sure what it is or why it works, I just discovered that it does. Is it safe to use?</p>
  
  <p>When I look at form fields created using <code>fields_for</code>, I see that it sets an numeric index for that middle array/hash (whatever it is), like so:</p>
  
  <pre><code>&lt;input id="children_attributes_0_name" name="parent[children_attributes][0][name]" type="text"&gt;
  </code></pre>
  
  <p>Unfortunately, I can't use <code>fields_for</code> because I have to add the hidden fields only when the "add" button is clicked.</p>
  
  <p>What's the right approach here?</p>