Skip to content

Commit

Permalink
make query method used for select filters more flexible
Browse files Browse the repository at this point in the history
As per my discussion with @t-anjan in activeadmin#1093
  • Loading branch information
seanlinsley authored and Aerlinger committed Jun 3, 2014
1 parent df4e512 commit 90d93dc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/active_admin/inputs/filter_select_input.rb
Expand Up @@ -4,11 +4,11 @@ class FilterSelectInput < ::Formtastic::Inputs::SelectInput
include FilterBase

# When it's a HABTM or has_many association, Formtastic builds "object_ids".
# Metasearch requires "objects_id", hence the convoluted override.
#
# We use "_in" instead of "_eq" since it works for single or multiple values.
# That doesn't fit our scenario, so we override it here.
def input_name
reflection ? "#{method}_id_in" : "#{method}_in"
name = method.to_s
name.concat '_id' if reflection
name.concat multiple? ? '_in' : '_eq'
end

# Include the "Any" option if it's a dropdown, but not if it's a multi-select.
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/filters/filter_form_builder_spec.rb
Expand Up @@ -223,7 +223,7 @@ def filter(name, options = {})
let(:body) { filter :author }

it "should generate a select" do
body.should have_tag "select", :attributes => { :name => "q[author_id_in]" }
body.should have_tag "select", :attributes => { :name => "q[author_id_eq]" }
end
it "should set the default text to 'Any'" do
body.should have_tag "option", "Any", :attributes => { :value => "" }
Expand Down

0 comments on commit 90d93dc

Please sign in to comment.