【发布时间】:2018-08-07 14:41:18
【问题描述】:
我在 ActiveAdmin 资源的索引视图中使用过滤器。
这是缩写来源:
ActiveAdmin.register PendingCollege do
config.clear_action_items!
controller do
include Sendable
end
filter :name
menu :parent => "College"
actions :all, :except => [:destroy, :edit]
scope :all do
PendingCollege
end
scope :pending, default: true do
PendingCollege.pending
end
scope :rejected do
PendingCollege.rejected
end
scope :accepted do
PendingCollege.accepted
end
index do
column :id
column "Name", :name
column "IPEDS Number", :ipeds_number
column "Local id", :local_id
end
end
我看到的行为是过滤器按预期显示在右侧。当我选择“包含”并将字符串放入框中并点击过滤器按钮时,它会使用默认范围重新加载页面,但结果根本没有被过滤。
我确认"q"=>{"name_contains"=>"Adrian"} 在控制器的参数中,但正在运行的 sql 没有利用它。
我基本上添加了一个过滤器(而不是每个属性的默认过滤器),因为我不需要在此界面中公开大量可搜索的属性。
我查看了很多代码示例,但没有发现任何需要添加额外代码来支持过滤器的地方。
【问题讨论】:
-
澄清一下,
Sendable是一个具有通过 http 将数据发送到远程 RESTful api 的方法的模块。