ruby-on-rails - 活跃的管理员过滤器

标签 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 个过滤器。我想创建一个名为“评论”的复选框,如果选中,我只想查找有评论的页面。我如何在事件管理员中执行此操作?提前致谢!

最佳答案

也许你想要这样的东西:

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

search_method doc

关于ruby-on-rails - 活跃的管理员过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9728027/

相关文章:

Ruby Liquid 模板嵌套哈希

jquery - JStree 设置链接 href 和重定向

javascript - 在 Rails 3 应用程序中添加页面特定 JavaScript 的最佳方法?

ruby - Ruby 中的双点符号

ruby-on-rails - 将类代码添加到事件管理仪表板

ruby-on-rails - 运行抽佣 Assets :precompile fails when there's no tables (yet)

ruby-on-rails - rails : I installed ActiveAdmin and my devise link stopped working

ruby-on-rails - 如何使用 rails 验证 reCAPTCHA?

ruby-on-rails - 删除 x 个尾随字符(如果存在)?

ruby-on-rails - 从 3.2.12 到 4.2.0 的 Rails 查询转换不返回任何内容