-3

The below is my class Ability. It means if you are admin you can do everything, else you just can read. But i don't know how to classify customers after they signed in? If you have any suggestion pls help me!

class Ability
  include CanCan::Ability

  def initialize(user)
    user ||= User.new # guest user (not logged in)
    if user.admin?
      can :manage, :all
    else
      can :read, :all
    end
  end
end
Michael Gaskill
  • 7,913
  • 10
  • 38
  • 43

1 Answers1

1

you can write a method in ApplicationController like:

def require_admin
 current_user.admin?
end

then in your desired controller, you can use

before_action :require_admin, except: :show

I guess I gave you an idea and you should improvise it.