title: Getting attributes in nested model rails 3.2
body: <p>I have two models user and profile.<br/>
  I want to save the username and password in user and other user profile details in 
  profile.<br/>
  Now,<br/>
  The user model has:</p>
  
  <pre><code>has_one :profile
  accepts_nested_attributes_for :profile
  attr_accessible :email, :password,:profile_attributes
  </code></pre>
  
  <p>The profile model has</p>
  
  <pre><code> belongs_to :user
   attr_accessible :firstname, :lastname
  </code></pre>
  
  <p>The user controller has</p>
  
  <pre><code> def new
      @user = User.new
      @profileattr = @user.build_profile
    end
  
    def create
      @user = User.new(params[:user])
  
      if @user.save
        redirect_to root_url, :notice =&gt; "user created successfully!"
      else
        render "new"
      end
    end
  </code></pre>
  
  <p>The view new.html.erb have fields for both user and profile.<br/>
  view has:</p>
  
  <pre><code>&lt;%= form_for @user do |f| %&gt;
    &lt;% if @user.errors.any? %&gt;
      &lt;div class="error_messages"&gt;
        &lt;h2&gt;Form is invalid&lt;/h2&gt;
        &lt;ul&gt;
          &lt;% for message in @user.errors.full_messages %&gt;
            &lt;li&gt;&lt;%= message %&gt;&lt;/li&gt;
          &lt;% end %&gt;
  
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
  
  
    &lt;p&gt;
      &lt;%= f.label :email %&gt;&lt;br /&gt;
      &lt;%= f.text_field :email %&gt;
    &lt;/p&gt;
    &lt;p&gt;
      &lt;%= f.label :password %&gt;&lt;br /&gt;
      &lt;%= f.password_field :password %&gt;
    &lt;/p&gt;
  
  
    &lt;%= f.fields_for @profileattr do |pf|%&gt;
    &lt;p&gt;
      &lt;%= pf.label :firstname %&gt;&lt;br /&gt;
      &lt;%= pf.text_field :firstname %&gt;
    &lt;/p&gt;
    &lt;p&gt;
      &lt;%= pf.label :lastname %&gt;&lt;br /&gt;
      &lt;%= pf.text_field :lastname %&gt;
    &lt;/p&gt;
    &lt;% end %&gt;
  
    &lt;p class="button"&gt;&lt;%= f.submit %&gt;&lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>However,when I run this web application it shows error:<br/><br/>
  <em>Can't mass-assign protected attributes: profile</em><br/><br/></p>
  
  <p>on debug I found the user has attributes as:</p>
  
  <pre><code> :email:abc@gmail.com
   :password:secret
  
   :profile
              ---:firstname:abc
              ---:lastname:xyz
  </code></pre>
  
  <p>so,instead of expected params[:profile_attributes] the view returning params[:profile]
  <br/>leading to mass-assignment error.so what is going wrong?</p>