Monday, November 5, 2012

Re: [Rails] has_one relation and form_for

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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate