主动管理过滤器

时间:2012-03-15 20:55:06

标签: ruby-on-rails ruby activeadmin

我有一个模型page.rb和模型comment.rb和评论belongs_to页面。 我也在使用gem active admin。在索引页面上,我有一个由"过滤器"制作的搜索表单,我有

  filter :country
  filter :city
  filter :category
  filter :description_type
  filter :title
  filter :sight_of_the_day, :as => :select
  filter :active, :as => :select
  filter :show_in_top, :as => :select
  filter :created_at
  filter :updated_at

它工作正常,但我想再增加1个过滤器。我想创建一个名为&#34的复选框;评论"如果选中它,我想查找只有评论的页面。我如何在主动管理员中执行此操作?提前谢谢!

1 个答案:

答案 0 :(得分:10)

也许你想要这样的东西:

filter :has_comments, :as => :select

这将生成带有“Any”,“Yes”,“No”选项的select。您还需要搜索方法“has_comments_eq”:

scope :has_comments_eq, lambda { |has| has == "true" ? with_comments : without_comments }
search_method :has_comments_eq

search_method doc

相关问题