0
votes

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 `Profile' for #

2

2 Answers

0
votes

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.

0
votes

I think that you should use

@profile = current_user.build_profile(params[:profile])

Check rails api here