Ruby on rails 权威政策将索引操作和视图限制为特定角色

Ruby on rails 权威政策将索引操作和视图限制为特定角色,ruby-on-rails,pundit,Ruby On Rails,Pundit,我试图使用此权威策略,不允许具有临床医生角色的用户访问患者控制器上的索引操作。范围部分目前正在按我所希望的那样工作,但根据目前编写的策略,我仍然可以作为临床医生用户访问/患者。我做错了什么?谢谢你的帮助 以下是我的角色定义: enum role: { staff: 0, clinician: 1, admin: 2 } def index @patients = policy_scope(Patient) end [rest of controller] 患者政策 class Pat

我试图使用此权威策略,不允许具有临床医生角色的用户访问患者控制器上的索引操作。范围部分目前正在按我所希望的那样工作,但根据目前编写的策略,我仍然可以作为临床医生用户访问/患者。我做错了什么?谢谢你的帮助

以下是我的角色定义:

enum role: { staff: 0, clinician: 1, admin: 2 }
def index
    @patients = policy_scope(Patient)
end
[rest of controller]
患者政策

class PatientPolicy < ApplicationPolicy
  class Scope
    attr_reader :user, :scope

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

    def resolve
      if user.admin?
        scope.all
      else
        scope.joins(:user).merge(User.where(university: user.university))
      end
    end
  end

def index?
  user.staff? or user.admin?
end

end

自己的目标:我需要将授权行添加到我的患者控制器中的索引操作中:

def index
    authorize Patient
    @patients = policy_scope(Patient)
end