Ruby on Rails Role based authentication system, how to work with different roles?

I am using Rails 4.1. I have 3 types of users, Admin, Leader, Worker, and each has its own page. I have selected developer + pundit for this role, but cannot figure out how to send users to different paths. For example, how can I take the admin to the admin section after sign_in and the Leader to leader section, can I restrict the entry to some types?

Will other stones help for this problem?

+3


source to share


1 answer


I don't know about the jewel. But something like this should work:

class HomeController < ApplicationController
  def after_sign_in_path_for(resource)
    if current_user.admin?
      redirect_to admin_path
    elsif current_user.leader?
      redirect_to leader_path
    else
      redirect_to worker_path
  end
end

      



after_sign_in_path_for

callback in development .

+1


source







All Articles