Hello everybody. I have two models user and user_information. the User has_one user_information and the UserInformation belongs_to user. Now I need to make a form_for to create the user information for an user. So I go to the following link: http://localhost:3000/users/1/user_informations/new a fill the form, with the user_id, and the other fields. But I get the following error:
Can't mass-assign protected attributes: user_id
I think the error is in the user_information#new view, in the form_form. This is the actual form
I think the form_for should be something like <%= form_for([@user_information, @user.user_information.bluild]) do |f| %> but it doesn't work. So I really really need your help, please.
Thanks Tommaso, It works, but the user_id has this User:0x007fe37d33b5e0
no User:1, is that ok???
Don't confuse the actual data (saved on db) and the representation of it in the views. You see the representation of the User model, which is composed of user attributes (like @user.id, etc.).
My advice is to play with rails console to clarify your doubts