0
votes

I am new in ROR and I am using Rails 5 version I have successfully created sign_in functionality from devise.

I am using devise for sign_in, sign_up etc.

I have created three roles: super_admin, manager and moderator.

super_admin have all manage permission but others don't.

get 'manager/dashboard', :as => 'manager_dashboard'
get 'moderator/dashboard', :as => 'moderator_dashboard'
get 'users/dashboard', :as => 'users_dashboard'
root "home#index"
devise_for :users 

I want after sign_in redirect to different controller actions using devise.

  • super_admin after sign_in redirect users#dashboard.
  • manager after sign_in redirect manager#dashboard.
  • moderator after sign_in redirect moderator#dashboard.
1

1 Answers

2
votes

You want to use after_sign_in_path.

In your ApplicationController, define a method after_sign_path_for(resource):

def after_sign_in_path_for(resource)
  if resource.super_admin?
    users_dashboard_path
  elsif resource.manager?
    manager_dashboard_path
  else
    moderator_dashboard_path
  end
end