【发布时间】:2014-04-02 12:24:37
【问题描述】:
我刚刚开始在 Rails 4 应用程序中使用 Pundit gem 进行授权。
一切正常,但我可以了解分页在索引操作中的工作方式。
我的控制器的索引操作如下所示:
def index
@records = policy_scope(Record)
end
我的 RecordPolicy 中的 Scope 类然后去:
class Scope < Struct.new(:user, :scope)
def resolve
if user.has_role? :admin
# get all records
else
# get user specific records
end
end
end
这一切都很好。我想知道我将如何处理分页。当然,这涉及传递页面参数等,我不确定如何在不继承 Scope 类的情况下执行此操作。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 pundit