Why is Pundit not coupled with Rolify like CanCanCan is?

前端 未结 2 777
感情败类
感情败类 2021-02-04 13:52

I am using Devise and interested in using Pundit but cannot find much on if it should be integrating with Rolify or if it is stand alone. CanCanCan works nicely with Rolify and

2条回答
  •  悲&欢浪女
    2021-02-04 13:59

    Why don't use them together? They can be easily used in a fashion like this

    class OrganisationPolicy
      def initialize(user, organisation)
        @user = user
        @organisation = organisation
      end
    
      def index?
        @user.has_role? :admin
      end
    
      def show?
        @user.has_role?(:admin) || @user.organisation == @organisation
      end
    end
    

    In fact, the thing that rolify and pundit are not coupled is something nice, and not a design failure ;)

提交回复
热议问题