title: Rails, nested attributes, created in new action,
body: <p>I have a order system where a user selects products that's being saved in a cookie. It is then retrieved by the system when continued to the order page.</p>
  
  <pre><code>@order = Order.new
  unless @cart.nil?
    @cart.each do | product |
      @order.quantities.build :product =&gt; product, :quantity =&gt; 1
    end
  end
  </code></pre>
  
  <p>However I want the user to be able to update the quantity which is a field in the quantity model that belongs to product and order.</p>
  
  <p>How can I access this newly made "@order.quantities" in my form view?</p>
  
  <pre><code>    &lt;%= simple_form_for(@order) do |f| %&gt;
      &lt;%= f.error_notification %&gt;
      &lt;%= f.simple_fields_for :quantities do |q| %&gt;
         &lt;%= q.input :quantity %&gt;
      &lt;% end %&gt;
      &lt;div class="form-actions"&gt;
          &lt;%= f.button :submit, :class =&gt; "main_button right" %&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;% end %&gt;
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>class Order &lt; ActiveRecord::Base
      has_many :quantities
      has_many :products, through: :quantities
  end
  
  class Quantity &lt; ActiveRecord::Base
      belongs_to :order, dependent: :destroy
      belongs_to :product
  end
  </code></pre>