Home > database >  Redirection admin and user in rails
Redirection admin and user in rails

Time:02-03

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.

CodePudding user response:

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

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

More info: https://www.rubydoc.info/github/plataformatec/devise/Devise/Controllers/Helpers:after_sign_in_path_for

  •  Tags:  
  • Related