ruby-on-railshttp-redirectdashboardrails-admin

Redirection admin and user in rails


I am facing an issue in redirection of admin and user to two different pages. I created an admin column and set it as boolean,

Used a gem 'rails_admin' to create admin dashboard. And it is working, like when admin_user is login in then only we have admin dashboard.

Now can anyone say how can I redirect both admin to admin home and user to user home page.


Solution

  • If you are using devise you can add to application_controller sth like this:

    def after_sign_in_path_for(resource)
      current_user.admin? ? admin_path : user_path
    end
    

    More info: https://www.rubydoc.info/github/plataformatec/devise/Devise%2FControllers%2FHelpers:after_sign_in_path_for