我需要一些关于采取以下措施的最佳方法的建议。
我以前在我的应用程序中有Tutor,Student,Reservation模型。
我想预约包含导师和学生。
目前我正在使用设计进行用户身份验证,我喜欢使用通用用户的想法,并且为用户定义了角色,因为很多人都使用了设计&可以可以。例如,它可以轻松创建管理员角色。 因此,我可以在用户中包含一个Tutor或Student角色。
现在我的问题是我不能再以我想要的方式使用关联,例如。
Reservation
belongs_to :Tutor
belongs_to :Student
因为我不再为每种类型的用户提供单独的模型。
我该怎么办?
我发现如果我有Tutor和Student的个人模型,那么在设计中我需要单独的链接来登录和编辑每种类型的用户。
添加类似问题的链接
Multipe relationships in Rails where the class name does not match the association name
答案 0 :(得分:1)
只需覆盖班级名称即可使用“用户”:
class Reservation < ActiveRecord::Base
belongs_to :tutor, :class_name => "User"
belongs_to :student, :class_name => "User"
end