From 90d93dc7005e42e173c07f11329227381b1ee730 Mon Sep 17 00:00:00 2001 From: Sean Linsley Date: Fri, 5 Jul 2013 00:48:33 -0500 Subject: [PATCH] make query method used for select filters more flexible As per my discussion with @t-anjan in #1093 --- lib/active_admin/inputs/filter_select_input.rb | 8 ++++---- spec/unit/filters/filter_form_builder_spec.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/active_admin/inputs/filter_select_input.rb b/lib/active_admin/inputs/filter_select_input.rb index e454a1f2109..2f8ba1ec1f4 100644 --- a/lib/active_admin/inputs/filter_select_input.rb +++ b/lib/active_admin/inputs/filter_select_input.rb @@ -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. diff --git a/spec/unit/filters/filter_form_builder_spec.rb b/spec/unit/filters/filter_form_builder_spec.rb index a7b854d9c4e..c6fd2c21cc8 100644 --- a/spec/unit/filters/filter_form_builder_spec.rb +++ b/spec/unit/filters/filter_form_builder_spec.rb @@ -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 => "" }