Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add custom filter to Active Admin?

Active Admin allows me to define filters that are displayed on the index page like so:

ActiveAdmin.register Promo do    filter :name   filter :address   filter :city   filter :state   filter :zip  end 

I would like to combine all the fields above into one, so that I can search for Promos that contain the search string in name or full address. My model already has a named scope that I can use:

class Promo < ActiveRecord::Base   scope :by_name_or_full_address, lambda { |q| where('name LIKE :q OR address LIKE :q OR city LIKE :q OR state LIKE :q OR zip LIKE :q', :q => "%#{q}%") } end 
like image 563
dkobozev Avatar asked Nov 02 '11 16:11

dkobozev


1 Answers

Active admin uses metasearch. For example you can do this:

filter :"subscription_billing_plan_name" , :as => :select, :collection => BillingPlan.all.map(&:name) 
like image 179
Ivan Avatar answered Sep 24 '22 08:09

Ivan