Pavel
Pavel

Reputation: 4400

active admin filter

I Have a model page.rb and model comment.rb and comment belongs_to page. Also i am using gem active admin. On index page i have a search form made by "filter", I have

  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

it works fine, but i want to have 1 more filter. I want to make a checkbox named "comments" and if it is checked, i want to find pages only which have comments. How i can do this in active admin? Thanks in advance!

Upvotes: 2

Views: 4796

Answers (1)

Ivan
Ivan

Reputation: 3297

Maybe you want something like this:

filter :has_comments, :as => :select

This will generate select with options "Any", "Yes", "No". Also you need search method "has_comments_eq":

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

search_method doc

Upvotes: 10

Related Questions