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
I found better way of doing that. You just need to add:
config.clear_sidebar_sections!
sidebar :filters do
render partial: 'search'
end
And then make form inside the _search
partial with the builder ActiveAdmin::FormBuilder
as it did in:
https://github.com/gregbell/active_admin/blob/master/lib/active_admin/filters/forms.rb
For more information how to do it, look to this gist:
https://gist.github.com/4240801
Another idea is to create class:
module ActiveAdmin
module Inputs
class FilterCustomStringInput < FilterStringInput
def input_name
"#{super}"
end
end
end
end
that will be able to invoke by as: :custom_string
, but I don't like that idea, because you can find soon, that you will need to create custom_select and so on...
To use a custom filter, you can create a scope function and add it as search_methods in the model.
For example, on my User model:
search_methods :role_eq
scope :role_eq, -> (role) { where("? LIKE ANY(roles)", role) }
Then in users.rb, I can use my scope as a custom filter:
filter :role, label: "Roles", as: :select, collection: %w[ student teacher parent ]