title: Nested Forms and Building associations
body: <p>I'm working on a add to cart form. It looks something like this</p>
  
  <pre><code>#Models
  Order.rb
    has_many :line_items
    accepts_nested_attributes_for :line_items, :allow_destroy =&gt; true
  
  LineItem.rb
    has_one :product
    belongs_to :order
  
  Product.rb
    belongs_to :line_item
  </code></pre>
  
  <p>I'd like to create a form in product#show to allow multiple related products to be added to the order/cart at once, basically <em>create or update a line item for each product</em>.</p>
  
  <p>Probably something like this in the view (HAML to keep it brief). </p>
  
  <pre><code>-form_for @order do |f|
   - if has_related?
     - for related in @products.related_products
       - f.field_for :line_item do |li_form|
         = li_form.text_field :quantity
         = li_form.hidden_field :product_id
         = related.product_name
  </code></pre>
  
  <p>What would it take to actually make something like this work?</p>