我有一些资源的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?
请求生成过滤器(但它会正确生成列)。我认为这是因为approved
是一种方法,如果approved_at
不是nil
,则返回true。在这种情况下如何编写过滤器?
答案 0 :(得分: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