title: Create and edit multiple records of the same model
body: <p>I'm quite new to Rails and to this Q&amp;A website! So hello everyone, I'm a French Rails tester. I have cross posted this question to Railsforum too, to have a better chance on getting an answer :) (<a href="http://railsforum.com/viewtopic.php?id=44238" rel="nofollow">http://railsforum.com/viewtopic.php?id=44238</a>)</p>
  
  <p>I need help on something. It seems simple, but in my opinion, not well documented (I browsed the web for 3 days without finding a clean answer. Some partial solutions here, but not a complete and clean one for a newbie!)</p>
  
  <p>I want to add some actions to a default scaffolded controller to handle creation and modification of multiple records in the same form.</p>
  
  <pre><code>rails generate scaffold Item title:string 
  </code></pre>
  
  <p>This is the sample scaffolded code:</p>
  
  <h1>app/controllers/items_controller.rb</h1>
  
  <pre><code>class ItemsController &lt; ApplicationController
    # GET /items
    # GET /items.xml
    def index
      @items = Item.all
  
      respond_to do |format|
        format.html # index.html.erb
        format.xml  { render :xml =&gt; @items }
      end
    end
  
    # GET /items/1
    # GET /items/1.xml
    def show
      @item = Item.find(params[:id])
  
      respond_to do |format|
        format.html # show.html.erb
        format.xml  { render :xml =&gt; @item }
      end
    end
  
    # GET /items/new
    # GET /items/new.xml
    def new
      @item = Item.new
  
      respond_to do |format|
        format.html # new.html.erb
        format.xml  { render :xml =&gt; @item }
      end
    end
  
    # GET /items/1/edit
    def edit
      @item = Item.find(params[:id])
    end
  
    # POST /items
    # POST /items.xml
    def create
      @item = Item.new(params[:item])
  
      respond_to do |format|
        if @item.save
          format.html { redirect_to(@item, :notice =&gt; 'Item was successfully created.') }
          format.xml  { render :xml =&gt; @item, :status =&gt; :created, :location =&gt; @item }
        else
          format.html { render :action =&gt; "new" }
          format.xml  { render :xml =&gt; @item.errors, :status =&gt; :unprocessable_entity }
        end
      end
    end
  
    # PUT /items/1
    # PUT /items/1.xml
    def update
      @item = Item.find(params[:id])
  
      respond_to do |format|
        if @item.update_attributes(params[:item])
          format.html { redirect_to(@item, :notice =&gt; 'Item was successfully updated.') }
          format.xml  { head :ok }
        else
          format.html { render :action =&gt; "edit" }
          format.xml  { render :xml =&gt; @item.errors, :status =&gt; :unprocessable_entity }
        end
      end
    end
  
    # DELETE /items/1
    # DELETE /items/1.xml
    def destroy
      @item = Item.find(params[:id])
      @item.destroy
  
      respond_to do |format|
        format.html { redirect_to(items_url) }
        format.xml  { head :ok }
      end
    end
  end
  </code></pre>
  
  <h1>app/views/items/new.html.erb</h1>
  
  <pre><code>&lt;h1&gt;New item&lt;/h1&gt;
  
  &lt;%= render 'form' %&gt;
  
  &lt;%= link_to 'Back', items_path %&gt;
  </code></pre>
  
  <h1>app/views/items/edit.html.erb</h1>
  
  <pre><code>&lt;h1&gt;Editing item&lt;/h1&gt;
  
  &lt;%= render 'form' %&gt;
  
  &lt;%= link_to 'Show', @item %&gt; |
  &lt;%= link_to 'Back', items_path %&gt;
  </code></pre>
  
  <h1>app/views/items/_form.html.erb</h1>
  
  <pre><code>&lt;%= form_for(@item) do |f| %&gt;
    &lt;% if @item.errors.any? %&gt;
      &lt;div id="error_explanation"&gt;
        &lt;h2&gt;&lt;%= pluralize(@item.errors.count, "error") %&gt; prohibited this item from being saved:&lt;/h2&gt;
  
        &lt;ul&gt;
        &lt;% @item.errors.full_messages.each do |msg| %&gt;
          &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt;
        &lt;% end %&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
  
    &lt;div class="field"&gt;
      &lt;%= f.label :title %&gt;&lt;br /&gt;
      &lt;%= f.text_field :title %&gt;
    &lt;/div&gt;
    &lt;div class="actions"&gt;
      &lt;%= f.submit %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>In my opinion, I need to add 4 methods to my Item controller:</p>
  
  <ul>
  <li>new_multiple : to initialize the new
  multiple form view </li>
  <li>create_multiple :
  to handle results from the new
  multiple form view </li>
  <li>edit_mulitple : to
  initialize the edit multiple form
  view </li>
  <li>update_mulitple : to handle
  results from the edit multiple form
  view</li>
  </ul>
  
  <p>Then, I need to create 2 new views:</p>
  
  <ul>
  <li>new_multiple.html.erb with code for a multiple record (5 in the same time) creation form</li>
  <li>edit_mulitple.html.erb with code for a multiple record (5 in the same time) edition form</li>
  <li>and maybe _partials to avoid DRY stuff...</li>
  </ul>
  
  <p>Anyone want to help me write these 4 actions and 2 views? I would really appreciate that. </p>
  
  <p>Thanks! :)</p>
  
  <p>Note : In my application items are children of parentItems but I DON'T WANT to use nested_form to create items in parentItems forms like in railscast 196 and 197.</p>