How to handle multiple user types in Rails?
I'm finding a good way to modeling User different types in the system. For registration, he/she can select to be a student, a mentor, or both. Being a student or a mentor has different set of properties. Student and mentor will have different profile template layout as well.
How wou开发者_运维百科ld you design your controllers and models for this kind of problem?
I would create a
User
which can hold aMentor
class and/or aStudent
class. This way your different properties are seperated from each other while the same properties still remain in theUser
class.
In the Controller you can render a template (or partial), depending on the instance the User holds. One for students, one for mentors and one for both.You could also use Inheritance (
User
as parent withMentor
,Student
andBoth
as childs). The key word you want to look into here isSingle Table Inheritance
.
Imho the problem is the both option. That's why I would prefer the 1st solution.
精彩评论