How to add custom filter to Active Admin?

后端 未结 8 2128
眼角桃花
眼角桃花 2020-12-25 11:04

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         


        
8条回答
  •  情深已故
    2020-12-25 11:27

    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...

提交回复
热议问题