0

In my Rails application with Devise, I plan to make multiple types of Users (Student, Teacher, and Admin). They have a number of shared attributes such as username, email, password, etc, but with some differences. Students will be able to interact with the content posted by teachers (and probably each other), Teachers can make classes and post content and interact with their students, and Admin will likely have control over most everything (including taking down users, content, etc.)

I am trying to figure out the best way to do this, and preferably with the least headaches as I am still new to Rails. Should I make multiple Devise Models, one for each type of User, or should I make multiple models inherit from User (which I believe is called Single table inheritance?) I am fairly open to trying either one, but I am unsure of which is the best way to go

mc92
  • 475
  • 5
  • 10
  • 1
    Devise does authentication, but in your examples, you're asking for authorization -- they aren't the same thing. Take a look at CanCanCan or Pundit or any of the many authorization gems out there, You may want to use Rollify or a home grown implementation of roles to make things easier. – MarsAtomic Sep 18 '16 at 02:33

1 Answers1

0

If you want different authorizations (for example Admin & User) level you can use Pundit.

If you have different roles with the same authorizations (like Student and Teacher in the same context) you should use Inheritance and Concerns, maybe defining a base controller from which all other controllers can derive.

davegson
  • 8,205
  • 4
  • 51
  • 71
Marco Sanfilippo
  • 293
  • 3
  • 19