Class: ApplicationPolicy::Scope

Inherits:
Scope
  • Object
show all
Defined in:
lib/generators/natural/install/templates/application_policy.rb

Instance Method Summary collapse

Instance Method Details

#anon_user_scopeObject



19
20
21
22
# File 'lib/generators/natural/install/templates/application_policy.rb', line 19

def anon_user_scope
  scope
  # scope.public # e.g. only display public data
end

#resolveObject

It is recommended to use per-role scopes for Users # simply extend the resolve method with conditions for each “role” and the name of the scope they should call.



6
7
8
9
10
11
12
# File 'lib/generators/natural/install/templates/application_policy.rb', line 6

def resolve
  if !user.is_a? User
    anon_user_scope
  else
    standard_user_scope
  end
end

#standard_user_scopeObject



14
15
16
17
# File 'lib/generators/natural/install/templates/application_policy.rb', line 14

def standard_user_scope
  scope
  # scope.where(user: user) # e.g. only show resources that belong to that user
end