title: Anyone know how to save many objects in one form?
body: <p>I am trying to save many <strong>new</strong> objects in a form to one <strong>pre-existing</strong> parent object.</p>
  
  <pre><code>- form_for :parent_object do |f|
  </code></pre>
  
  <p>This is the beginning of my form. And then within it, I would do:</p>
  
  <pre><code>  - 2.times do
      - fields_for :child_object do |f|
  </code></pre>
  
  <p>Now if I were to save this, it would render as an <strong>ParentObject_Controller</strong> Update action which would fail because Update doesn't identify new objects.</p>
  
  <p>So if I wanted to render the appropriate Save action, I would have to set up like this :</p>
  
  <pre><code>- form_for [@parent_object, @child_object] do |f|
    - 2.times do
      - fields_for :child_object do |f|
  </code></pre>
  
  <p>This form then renders the Save action, but <strong>only</strong> saves the last child_object.</p>
  
  <p>I would show you my controller, but there's hardly a point because its devastatingly erroneous. </p>
  
  <p>My question is, how would you save many <strong>new</strong> objects in a form to one <strong>pre-existing</strong> parent object?</p>
  
  <p>I have looked extensively at Ryan Bate's work, and many many other blogs and SO posts regarding this. Nothing seems to really point at specifically creating new child objects for one pre-existing parent object.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I am under the impression that I have to toggle the parent_object's controller actions for <code>def update</code>.</p>
  
  <pre><code>  elsif params[:parent_object][:child_object]
      @child_object = Child_Object.new(params[:child_object])
      if @child_object.valid? &amp;&amp; @parent_object.referrals &lt;&lt; @child_object
        redirect_to new_parent_object_child_object_path(@parent_object)
      else
        render :action =&gt; :new
      end
  </code></pre>
  
  <p>In debugger, if I I place a debugger at the root of <code>def update</code>, and I write :</p>
  
  <pre><code>&gt;&gt; params[:parent_object]
  #=&gt; nil
  </code></pre>
  
  <p>Interesting! That means that when child_object is send to parent_object controller, the params are not filled out for it. Haha, no idea what to do about it though..</p>
  
  <p>Unfortunately that code doesn't work, it was just my attempt at getting closer. ;)</p>