Module: ActiveAdmin::ViewHelpers::FilterFormHelper

Included in:
ActiveAdmin::ViewHelpers
Defined in:
lib/active_admin/view_helpers/filter_form_helper.rb

Instance Method Summary collapse

Instance Method Details

#active_admin_filters_form_for(search, filters, options = {}) ⇒ Object

Helper method to render a filter form



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/active_admin/view_helpers/filter_form_helper.rb', line 7

def active_admin_filters_form_for(search, filters, options = {})
  options[:builder] ||= ActiveAdmin::FilterFormBuilder
  options[:url] ||= collection_path
  options[:html] ||= {}
  options[:html][:method] = :get
  options[:html][:class] ||= "filter_form"
  options[:as] = :q
  clear_link = link_to(I18n.t('active_admin.clear_filters'), "#", :class => "clear_filters_btn")
  form_for search, options do |f|
    filters.each do |filter_options|
      filter_options = filter_options.dup
      attribute = filter_options.delete(:attribute)
      f.filter attribute, filter_options
    end

    buttons =  :div, :class => "buttons" do
      f.submit(I18n.t('active_admin.filter')) +
        clear_link +
        hidden_field_tag("order", params[:order]) +
        hidden_field_tag("scope", params[:scope])
    end

    f.form_buffers.last + buttons
  end
end