title: Rails Nested Forms Attributes not saving if Fields Added with jQuery
body: <p>I have a rails form with a nested form. I used Ryan Bates nested form with jquery tutorial and I have it working fine as far as adding the new fields dynamically. </p>
  
  <p>But when I go to submit the form it does not save any of the associated attributes. However if the partial builds when the form loads it creates the attribute just fine. I can not figure out what is not being passed in the javascript that is failing to communicate that the form object needs to be saved.</p>
  
  <p>Any help would be great.</p>
  
  <pre><code>class Itinerary &lt; ActiveRecord::Base
    accepts_nested_attributes_for :trips
  end
  </code></pre>
  
  <p>itinerary/new.html</p>
  
  <pre><code>&lt;% form_for ([@move, @itinerary]), :html =&gt; {:class =&gt; "new_trip" } do |f| %&gt;
  
    &lt;%= f.error_messages %&gt;
    &lt;%= f.hidden_field :move_id, :value =&gt; @move.id %&gt;
    &lt;% f.fields_for :trips do |builder| %&gt;
      &lt;%= render "trip", :f =&gt; builder %&gt;
    &lt;% end %&gt;
  &lt;%= link_to_add_fields "Add Another Leg to Your Trip", f, :trips %&gt;
  
  &lt;p&gt;&lt;%= f.submit "Submit" %&gt;&lt;/p&gt;
  
  &lt;% end %&gt;
  </code></pre>
  
  <p>application_helper.rb</p>
  
  <pre><code> def link_to_remove_fields(name, f)
    f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)")
   end
  
   def link_to_add_fields(name, f, association)
    new_object = f.object.class.reflect_on_association(association).klass.new
    fields = f.fields_for(association, new_object, :child_index =&gt; "new_#{association}") do |builder|
      render(association.to_s.singularize, :f =&gt; builder)
    end
    link_to_function(name, h("add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")"))
   end
  </code></pre>
  
  <p>application.js</p>
  
  <pre><code>function add_fields(link, association, content) {
  var new_id = new Date().getTime();
  var regexp = new RegExp("new_" + association, "g")
  $(link).parent().before(content.replace(regexp, new_id));
  }
  </code></pre>