开发者

Rails 3: After_save create profile

I have a user mo开发者_StackOverflow社区del 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


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


For a has_one association:

self.create_profile(params[:profile])

has_many

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜