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

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

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#current_filterObject


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

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


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

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

#filtersObject


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

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

#input_htmlObject


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

def input_html
  builder.text_field current_filter, input_html_options
end

#select_htmlObject


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

def select_html
  template.select_tag '', template.options_for_select(filter_options, current_filter)
end

#to_htmlObject


38
39
40
41
42
43
44
# File 'lib/active_admin/inputs/filters/base/search_method_select.rb', line 38

def to_html
  input_wrapping do
    label_html  << # your label
    select_html << # the dropdown that holds the available search methods
    input_html     # your input field
  end
end

#wrapper_html_optionsObject


32
33
34
35
36
# File 'lib/active_admin/inputs/filters/base/search_method_select.rb', line 32

def wrapper_html_options
  opts = super
  (opts[:class] ||= '') << ' select_and_search' unless seems_searchable?
  opts
end