Class: ActiveAdmin::Filters::FormBuilder

Inherits:
ActiveAdmin::FormBuilder show all
Includes:
FormtasticAddons
Defined in:
lib/active_admin/filters/forms.rb

Overview

This form builder defines methods to build filter forms such as the one found in the sidebar of the index page of a standard resource.

Instance Attribute Summary

Attributes inherited from ActiveAdmin::FormBuilder

#already_in_an_inputs_block

Instance Method Summary collapse

Methods included from FormtasticAddons

#column, #column_for, #has_predicate?, #humanized_method_name, #klass, #polymorphic_foreign_type?, #ransacker?, #reflection_for, #scope?, #searchable_has_many_through?, #seems_searchable?

Methods inherited from ActiveAdmin::FormBuilder

#assoc_heading, #cancel_link, #has_many, #has_many_actions, #sorted_children

Instance Method Details

#default_input_type(method, options = {}) ⇒ Object (protected)

Returns the default filter type for a given attribute. If you want to use a custom search method, you have to specify the type yourself.


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/active_admin/filters/forms.rb', line 22

def default_input_type(method, options = {})
  if method =~ /_(eq|equals|cont|contains|start|starts_with|end|ends_with)\z/
    :string
  elsif klass._ransackers.key?(method.to_s)
    klass._ransackers[method.to_s].type
  elsif reflection_for(method) || polymorphic_foreign_type?(method)
    :select
  elsif column = column_for(method)
    case column.type
    when :date, :datetime
      :date_range
    when :string, :text
      :string
    when :integer, :float, :decimal
      :numeric
    when :boolean
      :boolean
    end
  end
end

#filter(method, options = {}) ⇒ Object


12
13
14
15
16
# File 'lib/active_admin/filters/forms.rb', line 12

def filter(method, options = {})
  if method.present? && options[:as] ||= default_input_type(method)
    template.concat input(method, options)
  end
end