Skip to content

Commit a747248

Browse files
committed
make the string filter logic a little clearer
`input_name_simple` is only ever called when the method already matches a search condition so there's no need for it
1 parent cceb9f5 commit a747248

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

lib/active_admin/inputs/filter_check_boxes_input.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def selected_values
1313

1414
# Add whitespace before label
1515
def choice_label(choice)
16-
" #{super(choice)}"
16+
' ' + super
1717
end
1818

1919
# Don't wrap in UL tag

lib/active_admin/inputs/filter_string_input.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@ class FilterStringInput < ::Formtastic::Inputs::StringInput
44
include FilterBase
55
include FilterBase::SearchMethodSelect
66

7+
# If the filter method includes a search condition, build a normal string search field.
8+
# Else, build a search field with a companion dropdown to choose a search condition from.
79
def to_html
810
if search_conditions =~ method.to_s
911
input_wrapping do
1012
label_html <<
11-
builder.text_field(input_name_simple, input_html_options)
13+
builder.text_field(method, input_html_options)
1214
end
1315
else
14-
super
16+
super # SearchMethodSelect#to_html
1517
end
1618
end
1719

18-
def input_name_simple
19-
method.to_s.match(search_conditions) ? method : "#{method}_contains"
20-
end
21-
2220
def search_conditions
2321
/_(contains|starts_with|ends_with)\z/
2422
end

0 commit comments

Comments
 (0)