I am new to ruby on rails.
I have 2 models, user and user_profile.
user has_one user_profile.
User_profile belongs_to user.
when creating user I want to create user_profile, in one form get user
and user_profile and save both.How ca I do that.
Thanks for your help.
> >> @user = User.new(user_params)
>
> >> @user_profile = @user.build_user_profile(params[:user_profile])
>
> >
>
> > Have a look in log/development.log and you will see the parameters you
>
> > are posting and check they are ok. Also you can do thinks like
>
> > inserting puts statements into your code, so if you insert
>
> I found the reason but I can not solve it.
>
> user_profile is unpermitted parameter.
>
>
>
> I added
>
>
>
> def user_params
>
> params.require(:user).permit(:email, :password,
>
> :user_profile_attributes =>[])
>
> end
>
You need to add the attributes that are allowed for user_profile.
Fred
>
> >
>
> > You need to add the attributes that are allowed for user_profile.
>
>
>
>
> in fact i want to add all attributes of user_profile. for testing
>
> purpose I added firstname & lastname like this
>
> def user_params
>
> params.require(:user).permit(:email, :password,
>
> :user_profile_attributes => [:firstname, :lastname])
>
> end
>
>
>
> but still not working.
>
> user_profile is in unpermitted parameter.
>
>
There shouldn't really be any parameters of that name. It's not clear what changes you made after I suggested accepts_nested_attributes. In particular how you call fields_for in the view is very relevant.
Fred