Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't mass-assign protected attributes: profiles,
    primarykey
    data
    text
    <p>I read lot of related posts but can't find why it's not working for me. I still have a "can't mass-assign protected attributes: profiles"... What am I doing wrong ?</p> <p>I have a User model and a related Profile model with a one-to-one relationship. Here the <strong>User model (simplified)</strong></p> <pre><code>class User &lt; ActiveRecord::Base attr_accessible :email, :password, :password_confirmation, :profile_attributes, :profile_id has_secure_password has_one :profile accepts_nested_attributes_for :profile end </code></pre> <p><strong>the Profile model</strong></p> <pre><code>class Profile &lt; ActiveRecord::Base attr_accessible :bio, :dob, :firstname, :gender, :lastname, :user_id belongs_to :user end </code></pre> <p>my <strong>User controller</strong></p> <pre><code>def new @user = User.new respond_to do |format| format.html # new.html.erb format.json { render json: @user } end end def create @user = User.new(params[:user]) @user.build_profile respond_to do |format| if @user.save format.html { redirect_to @user, flash: {success: 'User was successfully created. Welcome !'} } format.json { render json: @user, status: :created, location: @user } else format.html { render action: "new" } format.json { render json: @user.errors, status: :unprocessable_entity } end end end </code></pre> <p>If it can be of any help, both User and Profile were scaffolded. </p> <p>I tried too with ':profiles_attributes' instead of 'profile_attributes' in the User attr_accessible, same problem...</p> <p>tried too, '@user.profiles.build' instead of '@user.build_profile' in the User controller... same result...</p> <p>Any help with some explanation would be great (I'm a noob on rails so forgive me)</p> <p><strong>EDIT The simple form I use</strong></p> <pre><code>&lt;%= simple_form_for(@user) do |f| %&gt; &lt;%= f.error_notification %&gt; &lt;%= f.simple_fields_for :profiles do |p| %&gt; &lt;div class="nested-form-inputs"&gt; &lt;%= p.input :lastname %&gt; &lt;%= p.input :firstname %&gt; &lt;/div&gt; &lt;% end %&gt; &lt;div class="form-inputs"&gt; &lt;%= f.input :email %&gt; &lt;%= f.input :password %&gt; &lt;%= f.input :password_confirmation %&gt; &lt;/div&gt; &lt;div class="form-actions"&gt; &lt;%= f.button :submit %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>Cheers </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload