2012-03-15 178 views
2

我有一个模型page.rb和模型comment.rb和评论belongs_to的页面。 还我使用的宝石主动管理。在索引页我有一个搜索表单的“过滤器”时,我有主动管理过滤

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个过滤器。我想打一个名为“意见”复选框,如果它被选中,我只想要查找其有意见的网页。我如何在活动管理员中执行此操作?提前致谢!

回答

10

也许你想是这样的:

filter :has_comments, :as => :select 

这将产生选择的选项“任何”,“是”,“否”。你也需要搜索方法 “has_comments_eq”:

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

search_method doc

+0

非常非常好的! – RubyFanatic 2012-08-29 19:12:57

+3

在最新ActiveAdmin,整合检索已被替换洗劫所以你需要使用'的ransacker'代替'search_method'。下面是一个[示例](https://github.com/ernie/ransack/blob/master/spec/support/schema.rb#L18)。 – manafire 2013-07-12 20:08:44