I have a rails app with authentication already set up using Devise. I’m adding CanCan and Role_Model. Adding abilities seems easy enough. However I’m unsure where to store the user’s role. Should I:
-
Add a column in the user db table for role?
-
Add a separate table or tables for role and role_user?
-
Add the role somewhere else?
This depends on how roles will be implemented in your application.
If roles will be inherited, for example
admin<registered user<guest, meaning that admin is able to do everythingreg. userandguestare capable of (and so on) then you may want to only add a singlerolefield on a common user model.If “actions” in your app a tied to a special roles that do not inherit permissions (unlike above), i.e. you need to have multiple roles on admin in order to do some common interaction with application (like guest does), then you need a join table, populated with
user_id, role_idpairs.I personally prefer the first option.