Class: ApplicationPolicy::Scope

Inherits:
Object
  • Object
show all
Defined in:
app/policies/application_policy.rb

Overview

Often, you will want to have some kind of view listing records which a particular user has access to. When using Pundit, you are expected to define a class called a policy scope.

Examples:

@posts = policy_scope(Post)

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, scope) ⇒ String

Initializer

Parameters:


64
65
66
67
# File 'app/policies/application_policy.rb', line 64

def initialize(user, scope)
  @user = user
  @scope = scope
end

Instance Attribute Details

#scopeObject (readonly)

`ActiveRecord::Relation` for filtering


58
59
60
# File 'app/policies/application_policy.rb', line 58

def scope
  @scope
end

#userObject (readonly)

Who try to access scope.


56
57
58
# File 'app/policies/application_policy.rb', line 56

def user
  @user
end

Instance Method Details

#resolveActiveRecord_Relation

Place logic here

Returns:

  • (ActiveRecord_Relation)

    customized scope


71
72
73
# File 'app/policies/application_policy.rb', line 71

def resolve
  scope.all
end