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, #label_from_options, #required?, #wrapper_html_options

Methods included from Filters::FormtasticAddons

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

Instance Method Details

#collectionObject

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



39
40
41
42
43
44
45
# File 'lib/active_admin/inputs/filter_select_input.rb', line 39

def collection
  if !options[:collection] && column
    pluck_column
  else
    super
  end
end

#include_blankObject

Provide the AA translation to the blank input field.



23
24
25
# File 'lib/active_admin/inputs/filter_select_input.rb', line 23

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

#input_html_options_nameObject

was “#object_name



28
29
30
# File 'lib/active_admin/inputs/filter_select_input.rb', line 28

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

#input_nameObject



6
7
8
9
10
# File 'lib/active_admin/inputs/filter_select_input.rb', line 6

def input_name
  return method if seems_searchable?

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



34
35
36
# File 'lib/active_admin/inputs/filter_select_input.rb', line 34

def multiple_by_association?
  false
end

#pluck_columnObject



47
48
49
# File 'lib/active_admin/inputs/filter_select_input.rb', line 47

def pluck_column
  klass.reorder("#{method} asc").uniq.pluck method
end

#searchable_method_nameObject



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

def searchable_method_name
  if searchable_has_many_through?
    "#{reflection.through_reflection.name}_#{reflection.foreign_key}"
  else
    name = method.to_s
    name.concat '_id' if reflection
    name
  end
end