【问题标题】:Active Admin filters not working活动管理员过滤器不起作用
【发布时间】: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 的方法的模块。

标签: ruby-on-rails activeadmin


【解决方案1】:

你应该像这样定义范围:

scope :pending, default: true do |scope|
  # given scope has all applied filters at this moment
  scope.pending
end

在您的情况下,由于您的模型中有同名的范围,您可以简单地这样做:

scope :all
scope :pending, default: true
scope :rejected
scope :accepted

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多