title: Add input to simple_form in javascript
body: <p>I have a rails 3 application where a user has_many addresses. I'm trying to make a form in which a user can add fields to create new addresses by clicking on a plus icon. The issue is that I can't add fields with correct name into my simple_form with javascript.</p>
  
  <p>The fields are well added to my view, but they all have the same name :  <code>user[addresses_attributes][0][name]</code> instead of <code>user[addresses_attributes][0 to x number][name]</code>. Because of that, I can't save new addresses... Can someone help me ?</p>
  
  <p>my edit_addresses.html.erb :</p>
  
  <pre><code>&lt;%= simple_form_for(current_user) do |f| %&gt;
    &lt;% current_user.addresses.each do |address| %&gt;
      &lt;div class="address_preview"&gt;
        &lt;%= f.simple_fields_for :addresses, address do |a| %&gt;
          &lt;%= a.input :name %&gt;
          &lt;%= a.input :description %&gt;
        &lt;% end %&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
  &lt;% end %&gt;
  &lt;a href='&lt;%= new_address_path(current_user) %&gt;' data-remote='true'&gt;Add&lt;/i&gt;&lt;/a&gt;
  </code></pre>
  
  <p>When a user click on "Add" he is redirect_to my new.js.html file:</p>
  
  <pre><code>$('#addresses_container').append('&lt;%= j render partial: 'new_address', locals: { target: @address } %&gt;');
  </code></pre>
  
  <p>And the 'new_address' partial is:</p>
  
  <pre><code>&lt;div class="address_preview"&gt;
    &lt;%= simple_form_for(current_user) do |f| %&gt;
      &lt;% f.simple_fields_for :addresses, target do |t| %&gt;
        &lt;%= t.input :name %&gt;
        &lt;%= t.input :description %&gt;
      &lt;% end %&gt;
    &lt;% end %&gt;
  &lt;/div&gt;
  </code></pre>