在我的应用程序策略中,我有一个方法'user_is_manager?'
application_poilcy.rb
class ApplicationPolicy
attr_reader :user, :record
def initialize(user, record)
@user = user
@record = record
end
.
.
.
def user_is_owner_of_record?
@user.id == record.created_by?
end
def user_is_manager?
@user.role_id == 1
end
end
我需要调用方法“ user_is_manager?”来自“ ApplicationPolicy”,位于“ post_policy”范围内
post_policy.rb
class PostPolicy < ApplicationPolicy
attr_reader :user, :record
def initialize(user, record)
@user = user
@record = record
end
class Scope < Scope
def resolve
if user_is_manager?
scope.all
else
raise Pundit::NotAuthorizedError, 'not allowed to view this action'
end
end
end
我怎么称呼它?