Rajdeep Singh
Rajdeep Singh

Reputation: 17834

How to add new profile for a particular user?

I have a user model and a profile model. In user.rb

has_one :profile

and in profile model

belongs_to :user

and when now I'm trying to create a profile for the current user in profiles#create

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

it throws an unknown method 'new' error. How to fix this problem? Please help?

Upvotes: 0

Views: 31

Answers (1)

Rajarshi Das
Rajarshi Das

Reputation: 12320

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

Upvotes: 1

Related Questions