[英]Multiple users with devise in the same model
I have a problem, i need create 3 type of users with devise. 我有一个问题,我需要设计出三种类型的用户。 these users have different fields.
这些用户具有不同的字段。 I thought about creating a table but would have many blank fields.
我考虑过要创建一个表,但是会有很多空白字段。
any recommendations? 有什么建议吗? I'm very confused.
我很困惑 I need a tutorial :)
我需要一个教程:)
Thanks friends. 谢谢朋友。
You are looking for something called Single Table Inheritance. 您正在寻找一种叫做“单表继承”的东西。 Basically you create one user model with devise which has a column "type" which is a string and you create sub models, like
基本上,您可以使用devise创建一个用户模型,该设计的列“ type”是字符串,然后创建子模型,例如
class Admin < User end
Class CMS < User
end
etc.... 等等....
Also, put all the common attributes in the User model 另外,将所有通用属性放入用户模型
Look at these links for an in-depth explanation. 请查看这些链接以获得更深入的说明。 STI is the solution.
STI是解决方案。 That much is sure
那可以肯定
http://samurails.com/tutorial/single-table-inheritance-with-rails-4-part-1/ http://samurails.com/tutorial/single-table-inheritance-with-rails-4-part-1/
devise and multiple "user" models 设计和多个“用户”模型
Unique IDs between Users and Admins with Devise Rails 使用Devise Rails的用户和管理员之间的唯一ID
Rails 4 Devise Multiple User Models STI Rails 4设计多用户模型STI
Stackoverflow ppl has already dealt with STI extensively! Stackoverflow ppl已经广泛处理了STI!
Hope these helps! 希望这些会有所帮助!
使用STI机制...或者您可以使用devise分隔所有表
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.