Skip to content

Strategies: Pundit authorization implemention

Matt Polito edited this page Apr 13, 2017 · 2 revisions

NOTICE - This is only valid for versions < 3

Using decent_exposure together with pundit, you get something similar to the load_and_authorize_resource that cancan 'used' to have.

Just use this custom strategy:

class PunditAuthorizationStrategy < DecentExposure::StrongParametersStrategy
  delegate :authorize, :policy_scope, to: :controller

  
  def collection_resource
    policy_scope super
  end
  
  def resource
    super.tap { |r| authorize r }
  end
end