我有一个模型 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 个过滤器。我想创建一个名为“评论”的复选框,如果选中,我只想查找有评论的页面。我如何在事件管理员中执行此操作?提前致谢!
最佳答案
也许你想要这样的东西:
filter :has_comments, :as => :select
这将生成带有选项“Any”、“Yes”、“No”的选择。您还需要搜索方法“has_comments_eq”:
scope :has_comments_eq, lambda { |has| has == "true" ? with_comments : without_comments }
search_method :has_comments_eq
关于ruby-on-rails - 活跃的管理员过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9728027/