I’m working on a project management app, and in the app, I have project_managers and clients. I’m using Devise and CanCan for authentication/authorization.
At what point after login should I be redirecting the user to their own specific controller/layout/views? Is there a way to check for current_user.role in routes.rb and set the root (or redirect) based on whether or not they’re a project manager or a client? Is this a change I can make in Devise somewhere?
Thanks in advance for any help!
–Mark
Your
routes.rbfile won’t have any idea what role the user has, so you won’t be able to use it to assign specific root routes.What you can do is set up a controller (for example,
passthrough_controller.rb) which in turn can read the role and redirect. Something like this:This way, all users will have one point of entry, which in turn redirects them to the appropriate controller/action depending on their role.