3

我有一些资源的 Active Admin 索引页面。

ActiveAdmin.register Request do
  index do
    column :created_at
    column :content
    column "Approved", :approved?
    default_actions
  end

  filter :created_at
  filter :content
  filter :approved?
end

问题是它不会为approved?请求生成过滤器(但它会正确生成列)。我认为这是因为is 一种方法,如果is notapproved则返回 true 。在这种情况下如何编写过滤器?approved_atnil

4

1 回答 1

1

试试这个使用范围创建一个过滤器按钮:

# model/request.rb
scope :approved, where("approved_at IS NOT NULL")

# or...if you have other default values on approved_at column you can try this
scope :approved, where("approved IS NOT", nil)
scope :approved, where("approved IS NOT ?", "")

#app/admin/requests.rb
scope :approved

有关 Active Admin 范围的更多信息:http: //activeadmin.info/docs/2-resource-customization.html#scoping_the_queries

于 2013-05-11T06:35:50.223 回答