Class: ActiveAdmin::Inputs::FilterSelectInput

Inherits:
Formtastic::Inputs::SelectInput
  • Object
show all
Includes:
FilterBase
Defined in:
lib/active_admin/inputs/filter_select_input.rb

Instance Method Summary collapse

Methods included from FilterBase

#collection_from_options, #input_wrapping, #required?, #wrapper_html_options

Methods included from Filters::FormtasticAddons

#column_for, #foreign_key?, #humanized_method_name, #polymorphic_foreign_type?, #reflection_for

Instance Method Details

#collectionObject

Provides an efficient default lookup query if the attribute is a DB column.



36
37
38
39
40
41
# File 'lib/active_admin/inputs/filter_select_input.rb', line 36

def collection
  unless Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR < 2
    return pluck_column if !options[:collection] && column_for(method)
  end
  super
end

#include_blankObject

Provide the AA translation to the blank input field.



20
21
22
# File 'lib/active_admin/inputs/filter_select_input.rb', line 20

def include_blank
  I18n.t 'active_admin.any' if super
end

#input_html_options_nameObject

was “#object_name



25
26
27
# File 'lib/active_admin/inputs/filter_select_input.rb', line 25

def input_html_options_name
  "#{object_name}[#{input_name}]"
end

#input_nameObject

If MetaSearch already responds to the given method, just use it.

Otherwise: When it’s a HABTM or has_many association, Formtastic builds “object_ids”. That doesn’t fit our scenario, so we override it here.



11
12
13
14
15
16
17
# File 'lib/active_admin/inputs/filter_select_input.rb', line 11

def input_name
  return method if @object.respond_to? method

  name = method.to_s
  name.concat '_id' if reflection
  name.concat multiple? ? '_in' : '_eq'
end

#multiple_by_association?Boolean

Would normally return true for has_many and HABTM, which would subsequently cause the select field to be multi-select instead of a dropdown.

Returns:

  • (Boolean)


31
32
33
# File 'lib/active_admin/inputs/filter_select_input.rb', line 31

def multiple_by_association?
  false
end

#pluck_columnObject



43
44
45
# File 'lib/active_admin/inputs/filter_select_input.rb', line 43

def pluck_column
  @object.base.reorder("#{method} asc").uniq.pluck method
end