How to initiate new profile object (has_one) after successful registration with Rails3 & devise
So I have devise setup to perform registration. After registration the user is redirected to profiles#new however I can't attach profile to current_user id
Actually it doesn't work at all. Here is what I have in my profiles_controller.rb
# POST /profiles
def create @profile = current_user.Profile.new(params[:profile])
respond_to do |format|
if @profile.save
format.html { redirect_to(@profile, :notice => 'Profile was successfully created.') }
else
format.html { render :action => "new" }
end
end
end
leading to undefined method开发者_StackOverflow社区 `Profile' for #
So the User
model has_one :profile
?
If so, you likely want:
@profile = current_user.profile.build(params[:profile])
Note that case ('profile' vs 'Profile') is important here.
I think that you should use
@profile = current_user.build_profile(params[:profile])
Check rails api here
精彩评论