开发者

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?


  1. I would create a User which can hold a Mentor class and/or a Student class. This way your different properties are seperated from each other while the same properties still remain in the User 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.

  2. You could also use Inheritance (User as parent with Mentor, Student and Both as childs). The key word you want to look into here is Single Table Inheritance.

Imho the problem is the both option. That's why I would prefer the 1st solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜