Search code examples
ruby-on-railsdeviseviewpartialspundit

Rails - Role based Views using Pundit


I am working on creating an app using Devise and Pundit to create users and assign them roles.

With that, I want to have role-based views in my app. I'm having a hard time thinking through how to make that possible.

When you login, if you're a user you should redirect to the user home view. If you're a manager you should redirect to a manager home view.

What's the best way, at a high level, to write that logic? Should it live in a controller, a view, perhaps utilize partials to keep things DRY....

Any tips are appreciated.


Solution

  • According to the Single Responsibility Principle, each object should do the smallest possible useful thing. For Rails controllers, that thing is handling requests and rendering views with associated objects. So I would put that in a controller.

    Devise has a great wiki on the subject of redirecting after a successful login.