donald
donald

Reputation: 23737

Rails 3: After_save create profile

I have a user model and a profile model that are tied together.

What I'd like to do is to create an user profile every time an user registers.

Here's what I have in the User model now:

 after_save :create_profile

  protected

  def create_profile
    @profile = current_user.build_profile(params[:profile])
    @profile.save
  end

However, it doesn't seem to work because current_user is not recognized, which makes sense, however, what's the way to fix this?

Thanks

Upvotes: 1

Views: 1008

Answers (2)

montrealmike
montrealmike

Reputation: 11631

For a has_one association:

self.create_profile(params[:profile])

has_many

self.profiles.create(params[:profile])

Upvotes: 0

Reuben Mallaby
Reuben Mallaby

Reputation: 5767

self.profile.create(params[:profile])

Upvotes: 2

Related Questions