Thanks Tomas. I tried this way, but then I get this error:

NoMethodError in UserInformationsController#new

undefined method `build' for nil:NilClass


On Monday, November 5, 2012 4:55:43 PM UTC-4:30, Tommaso Visconti wrote:
>
> Jean ha scritto: 
> > Can't mass-assign protected attributes: user_id 
>
> to solve this you need: 
>
> attr_accessible :user_id 
>
> in the UserInformation model, but you're using nested resources, so I'd 
> prefer something like: 
>
> # UserInformationController # 
>
> def new 
>    @user = User.find(params[:id]) 
>    @user_information = @user.user_information.build 
> end 
>
> def create 
>    @user = User.find(params[:id]) 
>    @user_information = UserInformation.new(params[:user_information]) 
>    @user_information.user = @user 
>    @user_information.save 
> end 
>
> take a look here: 
> http://stackoverflow.com/questions/2034700/form-for-with-nested-resources 
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/kM1IEGZ82uYJ.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to