Module: ActiveAdmin::Inputs::Filters::Base::SearchMethodSelect

Included in:
NumericInput, StringInput, TextInput
Defined in:
lib/active_admin/inputs/filters/base/search_method_select.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



21
22
23
# File 'lib/active_admin/inputs/filters/base/search_method_select.rb', line 21

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#current_filterObject



57
58
59
60
61
62
# File 'lib/active_admin/inputs/filters/base/search_method_select.rb', line 57

def current_filter
  @current_filter ||= begin
    methods = filters.map { |f| "#{method}_#{f}" }
    methods.detect { |m| @object.public_send m } || methods.first
  end
end

#filter_optionsObject



64
65
66
67
68
# File 'lib/active_admin/inputs/filters/base/search_method_select.rb', line 64

def filter_options
  filters.collect do |filter|
    [I18n.t("ransack.predicates.#{filter}").capitalize, "#{method}_#{filter}"]
  end
end

#filtersObject



53
54
55
# File 'lib/active_admin/inputs/filters/base/search_method_select.rb', line 53

def filters
  options[:filters] || self.class.filters
end

#input_htmlObject



45
46
47
# File 'lib/active_admin/inputs/filters/base/search_method_select.rb', line 45

def input_html
  builder.text_field current_filter, input_html_options
end

#select_htmlObject



49
50
51
# File 'lib/active_admin/inputs/filters/base/search_method_select.rb', line 49

def select_html
  template.select_tag "", template.options_for_select(filter_options, current_filter), "data-search-methods": ""
end

#to_htmlObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/active_admin/inputs/filters/base/search_method_select.rb', line 33

def to_html
  input_wrapping do
    [
      label_html, # your label
      '<div class="filters-form-input-group">',
      select_html, # the dropdown that holds the available search methods
      input_html, # your input field
      '</div>'
    ].join("\n").html_safe
  end
end