我有一个捆绑在一起的用户模型和个人资料模型。
我想做的是每次用户注册时都创建一个用户配置文件。
以下是我现在在用户模型中的内容:
after_save :create_profile
protected
def create_profile
@profile = current_user.build_profile(params[:profile])
@profile.save
end
但是,它似乎无法正常工作,因为无法识别current_user,这是有道理的,然而,解决这个问题的方法是什么?
由于
答案 0 :(得分:2)
self.profile.create(params[:profile])
答案 1 :(得分:0)
对于has_one关联:
self.create_profile(PARAMS [:资料])
的has_many
self.profiles.create(PARAMS [:资料])