title: Rails: add form in index page of a nested resource
body: <p>models:</p>
  
  <p>Order <strong>has_many</strong> Materials<br>
  Material <strong>belongs_to</strong> Order</p>
  
  <p><strong>materials_contrller.rb</strong></p>
  
  <pre><code> def index
      @order = Order.find_by_id(params[:order_id])
      @materials = @order.materials
    end
  
  def update
      @order = Order.find_by_id(params[:order_id])
      @material = @order.materials.find_by_id(params[:id])
  
      if @material.update_attributes(material_params)
        redirect_to order_materials_path(@order)
      else
        render 'edit'
      end 
  end
  </code></pre>
  
  <p>I want to add a form in materials index page , <strong>index.html.erb</strong></p>
  
  <pre><code>    &lt;% @materials.each do |material| %&gt;
                  &lt;%= form_for material, url: {controller:"materials", action: "update"} do |f| %&gt;
                  &lt;%= f.check_box :material_urgent %&gt;
                  &lt;%= f.submit %&gt;
                  &lt;% end %&gt;
  &lt;%end%&gt;
  </code></pre>
  
  <p>but I got an error when I tried it on page <br><strong><a href="http://localhost:3000/orders/1/materials" rel="nofollow">http://localhost:3000/orders/1/materials</a></strong></p>
  
  <pre><code>ActionController::UrlGenerationError in Materials#index
  No route matches {:action=&gt;"update", :controller=&gt;"materials", :order_id=&gt;"1"}
  </code></pre>
  
  <p>Anybody could help? Thanks!</p>