title: Rails - Accepts_nested_attributes_for mass assignment error
body: <p>I am currently trying to set up a form with nested fields on a belongs_to relationship, but I am running into a mass assignment error. My code so far is as follows (some html removed):</p>
  
  <p>Sale model:</p>
  
  <pre><code>class Sale &lt; ActiveRecord::Base
    attr_accessible :customer_attributes
    belongs_to :customer
    accepts_nested_attributes_for :customer
  end
  </code></pre>
  
  <p>new.html.erb:</p>
  
  <pre><code>&lt;div class="container"&gt;
    &lt;%= form_for :sale, :url =&gt; sales_path do |sale| -%&gt;
      &lt;%= sale.fields_for :customer do |customer_builder| %&gt;
        &lt;%= render :partial =&gt; "customers/form", :locals =&gt; {:customer =&gt; customer_builder, :form_actions_visible =&gt; false} %&gt;
      &lt;% end -%&gt;
    &lt;% end -%&gt;
  </code></pre>
  
  <p>customers/_form.html.erb</p>
  
  <pre><code>&lt;fieldset&gt;
    &lt;label class="control-label"&gt;Customer Type&lt;/label&gt;
    &lt;%= collection_select(:customer, :customer_type_id, CustomerType.all, :id, :value, {}, {:class =&gt; "chzn-select"}) %&gt;
  &lt;/fieldset&gt;
  </code></pre>
  
  <p>I believe this should allow me to create a Sale object, and a nested Customer object. The parameters being sent are (note some unrelated params are included):</p>
  
  <pre><code>{"utf8"=&gt;"✓",
  "authenticity_token"=&gt;"qCjHoU9lO8VS060dXFHak+OMoE/GkTMZckO0c5SZLUU=",
  "customer"=&gt;{"customer_type_id"=&gt;"1"},
  "sale"=&gt;{"customer"=&gt;{"features_attributes"=&gt;{"feature_type_id"=&gt;"1",
  "value"=&gt;"jimmy"}}},
  "vehicle"=&gt;{"trim_id"=&gt;"1",
  "model_year_id"=&gt;"1"}}
  </code></pre>
  
  <p>The error I am getting is:</p>
  
  <pre><code>Can't mass-assign protected attributes: customer
  </code></pre>
  
  <p>I can see why this might be the case, since :customer is not in the attr_accessible list for Sale - though shouldn't the form be sending customer_attributes instead of customer?</p>
  
  <p>Any help / advice appreciated.</p>
  
  <p>EDIT 1: As far as I can tell, attr_accessible in the Sale model should be covered with :customer_attributes - if anyone says different, please let me know.</p>
  
  <p>EDIT 2: I have tried various permutations, but I can not seem to get the parameters to send customer_attributes instead of simply customer - perhaps I have missed a tag or used an incorrect tag somewhere in the forms above?</p>
  
  <p>EDIT 3: I have found another question on SO that indicated a problem with the <code>:url =></code> part on the form_for tag - the question was referring to a formtastic setup, but I'm wondering if that could be what is causing the problem here?</p>