Search code examples
ruby-on-rails-4devisecancanrolifypundit

Why is Pundit not coupled with Rolify like CanCanCan is?


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 I like the roles model. Am I missing a major reason why Pundit and Rolify do not seem to be used together a lot?


Solution

  • 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 ;)