How to integrate CanCan with multiple devise models?

后端 未结 3 1458
感情败类
感情败类 2021-01-02 01:22

How would I go about defining abilities for several devise models?

3条回答
  •  离开以前
    2021-01-02 01:29

    This worked for me -

    class Ability
      include CanCan::Ability
    
      def initialize(user)
        if user.is_a?(Admin)
          can :manage, :all
        elsif user.is_a?(User)
          can :create, Comment
          can :read, :all
        else
          can :read, :all
        end
      end
    end
    

提交回复
热议问题