title: Rails 3.2 has_many through form submission
body: <p>I have a has_many :through form where I can't get an extra attribute to post to the database.  I'm fouling up the parameter name somewhere.  I can get the foreign keys to post but I have another attribute that I'm trying to track in the join table. Keep in mind this is a 100% ajax based form. Here's what I know</p>
  
  <p>Edit:
  After researching similar issues, I understand I'm supposed to build the form attributes, but the code I've found doesn't work for some reason. Here are some resources.  </p>
  
  <p><a href="http://railsforum.com/viewtopic.php?id=20203" rel="nofollow noreferrer">http://railsforum.com/viewtopic.php?id=20203</a></p>
  
  <p><a href="https://stackoverflow.com/questions/4671740/rails-3-nested-multi-level-forms-and-has-many-through">Rails 3, nested multi-level forms and has_many through</a></p>
  
  <p>What I don't understand is that attaching the product_ids is built into rails.  Those values post.  Why is it hard to attach the quantity_shipped attribute to that array?</p>
  
  <pre><code>Models and Relationships
    Shipment  has_many :products :through =&gt; :product_shipments
    Product   has_many :shipments :through =&gt; :product_shipments
    ProductShipments belongs_to :shipment,  belongs_to :product
  
  ProductShipments table
    t.integer    :shipment_id  
    t.integer    :product_id
    t.integer    :qty_shipped  &lt;-- This is the Problem Child
  </code></pre>
  
  <p>This partial is looped through a few times displaying all the products from a certain vendor.  It generates an array for the product_ids and another for the product_shipments quantities.</p>
  
  <p>_product_shipments.html.erb.  </p>
  
  <pre><code>&lt;div id="product_shipments_container"&gt;
  &lt;h3&gt;Assign Products to Ship&lt;/h3&gt;
  &lt;ul class="product_shipments" id="product_shipments"&gt;
    &lt;% Product.by_client(@client_id).each do |product| %&gt;
      &lt;%= content_tag_for :li, product, :value =&gt; product.id do %&gt;
        &lt;%= hidden_field_tag("shipment[product_ids][]", product.id) %&gt;
        &lt;%= product.product_name %&gt;&lt;%= text_field_tag("product_shipments[qty_shipped]")%&gt; &lt;--This is where the issue lies
      &lt;% end %&gt;
    &lt;% end %&gt;
  &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This is the relevant POST data when the form is submitted</p>
  
  <pre><code>"product_ids"=&gt;["1", "3"]}, "product_shipments"=&gt;{"qty_shipped"=&gt;["32", "23"]}
  </code></pre>
  
  <p>This is sql that is sent to the database</p>
  
  <pre><code>INSERT INTO `product_shipments` (`product_id`, `qty_shipped`, `shipment_id`) 
  VALUES (1, NULL, 155)
  INSERT INTO `product_shipments` (`product_id`, `qty_shipped`, `shipment_id`)
  VALUES (3, NULL, 155)
  </code></pre>
  
  <p>Here is the action in my controller</p>
  
  <pre><code>def create
   @shipment = Shipment.new(params[:shipment])
  
   @product_shipments = @shipment.product_shipments.build(params[:product_shipments])
  </code></pre>
  
  <p>[:qty_shipped]) &lt;- not correct, but it's what i got so far
       if @shipment.save
         respond_with @shipment, :location => shipments_url
       else
         flash[:notice]= "Not saved"
       end
      end</p>
  
  <p>Here's the last issue I'm having.</p>
  
  <pre><code>TypeError (can't convert Symbol into Integer):
    app/controllers/shipments_controller.rb:24:in `[]'
    app/controllers/shipments_controller.rb:24:in `create'
  </code></pre>
  
  <p>GOT IT.  After making the changes with the correct answer below.  I was able to correct the controller to the following</p>
  
  <pre><code>@product_shipments = @shipment.product_shipments.build(params[:product_shipments])
  </code></pre>