I have two models user and profile.
I want to save the username and password in user and other user profile details in profile.
Now,
The user model has:
has_one :profile
accepts_nested_attributes_for :profile
attr_accessible :email, :password
The profile model has
belongs_to :user
attr_accessible :bio, :birthday, :color
The user controller has
def new
@user = User.new
@profile = @user.build_profile
end
def create
@user = User.new(params[:user])
@profile = @user.create_profile(params[:profile])
if @user.save
redirect_to root_url, :notice => "user created successfully!"
else
render "new"
end
end
The view new.html.erb have fields for both user and profile.
However,when I run this web application it shows error:
Can't mass-assign protected attributes: profile
on debug it stuck at @user = User.new(params[:user]) in create action
so,what is wrong? I have also tried putting :profile_attributes in attr_accessible but it doesn't help!
please help me to find out solution.