[英]Rails STI for User model with associations and authentication
我正在开发一个站点,医生可以管理他们的病人,约会等。一个医生可以有多个助手来帮助他们进行这些活动,并且一个助手可以属于多个医生。
医生和助手都应该能够使用相同的登录表单登录,但是出于明显的原因,他们根据角色具有不同的权限和关联,例如,患者与医生关联,而不与助手关联。
您如何建议将是解决此问题的最佳方法? 我正在考虑为授权部分使用CanCan,对于身份验证部分可以使用Doctor和Assistant可以继承的User模型的STI,但是STI是否可以处理这两个模型之间的HABTM,以及每个模型可能具有的其他关联?
提前谢谢
这应该可以解决问题。
只要确保您使用“类型”来设置用户身份即可。 然后,您可以使用以下内容:
current_user.is_doctor?
确定进入区域。
module User
def is_doctor?
true if self.type == Doctor
end
def is_assistant?
true if self.type == Assistant
end
end
module Doctor < User
has_and_belongs_to_many :assistants, :through => "assistant_assignments"
end
module Assistant < User
has_and_belongs_to_many :doctors, :through => "assistant_assignments"
end
喊,如果您需要更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.