Module: ActiveAdmin::Filters::ViewHelper

Defined in:
lib/active_admin/filters/forms.rb

Overview

This module is included into the view

Instance Method Summary collapse

Instance Method Details

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

Helper method to render a filter form


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/active_admin/filters/forms.rb', line 49

def active_admin_filters_form_for(search, filters, options = {})
  defaults = { builder: ActiveAdmin::Filters::FormBuilder,
               url: collection_path,
               html: {class: 'filter_form'} }
  required = { html: {method: :get},
               as: :q }
  options  = defaults.deep_merge(options).deep_merge(required)

  form_for search, options do |f|
    filters.each do |attribute, opts|
      next if opts.key?(:if)     && !call_method_or_proc_on(self, opts[:if])
      next if opts.key?(:unless) &&  call_method_or_proc_on(self, opts[:unless])

      f.filter attribute, opts.except(:if, :unless)
    end

    buttons =  :div, class: "buttons" do
      f.submit(I18n.t('active_admin.filters.buttons.filter')) +
        link_to(I18n.t('active_admin.filters.buttons.clear'), '#', class: 'clear_filters_btn') +
        hidden_field_tags_for(params, except: except_hidden_fields)
    end

    f.template.concat buttons
  end
end