Active Admin allows me to define filters that are displayed on the index page like so:
ActiveAdmin.register Promo do
filter :name
filter :address
filt
Answering in 2018. ActiveAdmin uses Ransack.
On model itself you need to add Ransack formatter:
ransacker :my_custom_filter, formatter: -> (category_id) {
ids = MyModel.where(category_id: category_id).pluck(:id) # return only id-s of returned items.
ids.present? ? ids : nil # return ids OR nil!
} do |parent| # not sure why this is needed .. but it is :)
parent.table[:id]
end
In ActiveAdmin file you need to specify the rule:
filter :my_custom_filter_in, as: :select, collection: -> { Category.all } # sometimes my_custom_filter_eq - depending on what you want .. Specify different "as" when you need it.