我有一个Rails应用程序。我安装了Devise。我想在用户模型和不同的配置文件之间有一个多态关联,例如:Student和Mentor。为不同的用户配置文件设计多态关联的用户
这就是我想要做的:有一个学生注册页面,例如:email
,password
,password_confirmation
。但是,我也希望有特定的学生档案领域,如residency_type
和graduation_year
user.rb
class User < ActiveRecord::Base
belongs_to :profile, polymorphic: true
student_profile.rb
class StudentProfile < ActiveRecord::Base
has_one :user, as: :profile, dependent: :destroy
registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
def new_student_registration
resource = build_resource({})
respond_with resource
end
...
我可以创建一个控制台,像这样的学生配置文件的用户...
u = User.new
u.email = "[email protected]"
... (password and password confirmation)
u.profile = StudentProfile.new
u.graduation_year = "2014"
u.save
问题是,我无法弄清楚如何设置控制器和一个窗体来做到这一点。我该怎么做?请注意用户和学生档案之间的关系。
你解决了这个问题吗?你介意发回你的解决方案吗? – brg 2013-04-24 03:03:43