Skip to content

update documentation on overriding authorize for namespaced policies #859

@wrkrb33

Description

@wrkrb33

The docs recommend overriding the authorize helper for controllers using namespaced policies like so:

  def authorize(record, query = nil)
    super([:admin, record], query)
  end

In my experience this worked fine under ruby 2.x, but is problematic (e.g., ignores policy_class arguments, which I need to avoid having pundit look for subclass-specific polices when using rails STI) under 3.x. I think what is actually needed is:

  def authorize(record, query = nil, policy_class: nil)
    super([:admin, record], query, policy_class: policy_class)
  end

or more generally and probably better:

  def authorize(record, query = nil, **kwargs)
    super([:admin, record], query, **kwargs)
  end

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions