我想推翻被设计的
RegistrationsContollers
'创建操作,以便当用户注册时,我可以将
UserProfile
与该用户一起建模。
因此,按照designe自述文件中的指导原则,我重写该操作:
#File app/controllers/registrations_controller.rb:
class Users::RegistrationsController < Devise::RegistrationsController
def create
# some code here..
self.user_profiles.build #Error (no method `user_profiles`)
current_user.user_profiles.build #Error (current_user is nil)
some other way???
end
end
#File routes.rb:
devise_for :users, :controllers => { :registrations => 'users/registrations' }
设计人员正在
users
表,但是我如何关联
用户配置文件
有那个记录吗?
我试过用谷歌搜索,但我就是没法用!任何帮助都非常感谢。
(我现在在Rails3.0.3上使用Devise1.1.5)
解决了的:
添加有利于他人的解决方案:
#File app/controllers/registrations_controller.rb:
class Users::RegistrationsController < Devise::RegistrationsController
def create
super
@user.build_user_profile
@user.user_profile.some_data = 'abcd'
@user.save!
end
end