CanCan的筛选器索引 [英] Filter index for CanCan
问题描述
我正在尝试根据能力过滤索引。我正在使用 wice_grid gem在索引中创建表格,并为票证添加条件,可以使用:conditions 。
I am trying to filter the index according to the ability. I am using the wice_grid gem to make a table in the index, and to add a condition to tickets, we could use something called :conditions.
我试图这样说:
@tickets_grid = initialize_grid(Ticket,
:include => [:user, :employee_department, :state],
:conditions => [Ticket.accessible_by(current_ability)])
这是行不通的。我正在寻找任何建议。
This is not working, though. I'm looking for any suggestions.
更新::conditions
的工作方式如 ActiveRecord
所以我想我需要一个查询来查找角色并检测当前能力
Update: :conditions
is working like ActiveRecord
so I guess I need a query to look up through roles and detect the current ability
推荐答案
您正在寻找的是current_ability.model_adapter(Ticket,:index).conditions其中Ticket是您的模型,而:index是您的访问类型。
What you are looking for is current_ability.model_adapter(Ticket, :index).conditions where Ticket is your model and :index is your access type.
因此在您的情况下应该是:
so in your case it should be:
@tickets_grid = initialize_grid(Ticket,:include => [:user, :employee_department, :state],:conditions => current_ability.model_adapter(Ticket, :index).conditions)
https://github.com/ryanb/cancan/wiki/Fetching-Records
这篇关于CanCan的筛选器索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!