Rails 4 - Pundit, Scopes: Getting Started

对着背影说爱祢 提交于 2019-12-08 20:15:30

ok, on the Pundit docs: https://github.com/elabs/pundit

the example seems to suggest that the Policy Scope need to inherit from applicationPolicy's scope:

class PostPolicy < ApplicationPolicy
  class Scope < Scope

so my guess is that you should try this:

class EoiPolicy < ApplicationPolicy
  class Scope < Scope # this is the changed line of code

Likewise, the application policy you have has the attr_readers outside of the Scope where the pundit examples have them inside eg:

class ApplicationPolicy
  # should not be here
  # attr_reader :user,  :scope

  class Scope
    # should be here instead
    attr_reader :user,  :scope

which might get you past the issue where you're deep-diving into the @-var here when you should just need the reader:

def resolve
  # selects all the EOI's for a given user
  # should not use `@scope`
  # @scope.where(user_id: @user.id)
  # instead use `scope` which is the reader
  scope.where(user_id: @user.id)
end

Regardless of whether this fixes your bug... you probably need to do these things :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!