fields for child_index not changing for nested_attributes
<p>I am using nested_attributes for has many associations. The nested attributed is added dynamically. </p>

<p>The association is Invoice has_many Items</p>

<p>Contoller code: </p>

<pre><code>def new
  @invoice = Invoice.new
  @invoice.items.build    
end
</code></pre>

<p>new.html.erb</p>

<pre><code>&lt;%= simple_form_for(@invoice,:format =&gt; :js,:method =&gt; :post, :post =&gt; true,:url =&gt; invoices_path, :required =&gt; true) do |f|%&gt;
   &lt;%= f.fields_for :items do |builder| %&gt;
        &lt;%= builder.text_field :fullname %&gt;
   &lt;% end %&gt;
   &lt;%= f.fields_for :items do |builder| %&gt;
        &lt;%= builder.text_field :fullname %&gt;
   &lt;% end %&gt;
   &lt;script type="text/javascript"&gt;
       $('#btnAddItemtoInvoice').on('click', function(){ 
            $('.exp').append("&lt;%= escape_javascript(render partial: 'item_fields.html.erb', locals: {f: f}) %&gt;")
         })
   &lt;/script&gt;
 &lt;% end %&gt;
</code></pre>

<p><strong>For first two row the child index is incremented properly but for rows from partials are not incremented. Child index I am getting is: 0,1,2,2,2 and so on.</strong></p>

<p>Partial: _item_fields.html.erb</p>

<pre><code>&lt;%= f.fields_for :items do |builder| %&gt;
    &lt;%= builder.text_field :fullname %&gt;
&lt;% end %&gt;
</code></pre>

<p>Why the child_index are not incrementing? How can I increment the child_index here?  </p>