J
J
Japanmama2016-02-04 23:13:06
ruby
Japanmama, 2016-02-04 23:13:06

Gem Pundit. How to create/use a generic method?

When connecting the pundit gem, we faced the following question: How to create / use a method in the main policy file (application_policy) that will be available to the entire application, and not to a specific policy (the policy that you created yourself).
example:
file application_policy.rb:
class ApplicationPolicy
attr_reader :current_user, :record
...
def check_access(view_name, type_access)
....
return res
end
how to use this method(check_access) in methods of other policies,
I would like to get the following result:
email_policy.rb file:
class EmailPolicy
attr_reader :current_user, :record
...
def update?
if check_access('emails',1)
true
else
false
end
end
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vsuhachev, 2016-02-05
@JapanMama

Use inheritance?
class EmailPolicy < ApplicationPolicy

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question