Ruby on rails 3 如何在成功注册Rails3&;后启动新的配置文件对象(有一个);发明
因此,我设计了一个执行注册的设置。注册后,用户被重定向到配置文件#新建,但我无法将配置文件附加到当前的#用户id 事实上它根本不起作用。以下是我在profiles_controller.rb中的内容Ruby on rails 3 如何在成功注册Rails3&;后启动新的配置文件对象(有一个);发明,ruby-on-rails-3,devise,has-one,Ruby On Rails 3,Devise,Has One,因此,我设计了一个执行注册的设置。注册后,用户被重定向到配置文件#新建,但我无法将配置文件附加到当前的#用户id 事实上它根本不起作用。以下是我在profiles_controller.rb中的内容 # POST /profiles def创建 @profile=当前用户.profile.new(参数[:profile]) 结束 导致#的未定义方法“Profile”,因此用户模型有一个:Profile 如果是这样,您可能需要: @profile = current_user.profile.b
# POST /profiles
def创建
@profile=当前用户.profile.new(参数[:profile])
结束
导致#的未定义方法“Profile”,因此
用户
模型有一个:Profile
如果是这样,您可能需要:
@profile = current_user.profile.build(params[:profile])
请注意,case(‘profile’vs‘profile’)在这里很重要。我认为您应该使用
@profile = current_user.build_profile(params[:profile])
检查谢谢。不幸的是,对于nil:NilClass,未定义的方法“build”会发生这样的情况。当我分两步完成时,它就工作了。有什么原因吗#@user=current_user#@profile=@user.create_profile(参数[:profile]您确定您在
用户
模型上有一个有一个:profile
(或属于_-to:profile
…取决于哪个有外键)?
@profile = current_user.build_profile(params[:profile])