-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
filter_select_input.rb
53 lines (44 loc) · 1.33 KB
/
filter_select_input.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
module ActiveAdmin
module Inputs
class FilterSelectInput < ::Formtastic::Inputs::SelectInput
include FilterBase
def input_name
return method if seems_searchable?
searchable_method_name.concat multiple? ? '_in' : '_eq'
end
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
# Provide the AA translation to the blank input field.
def include_blank
I18n.t 'active_admin.any' if super
end
# was "#{object_name}[#{association_primary_key}]"
def input_html_options_name
"#{object_name}[#{input_name}]"
end
# Would normally return true for has_many and HABTM, which would subsequently
# cause the select field to be multi-select instead of a dropdown.
def multiple_by_association?
false
end
# Provides an efficient default lookup query if the attribute is a DB column.
def collection
if !options[:collection] && column
pluck_column
else
super
end
end
def pluck_column
klass.reorder("#{method} asc").uniq.pluck method
end
end
end
end