searchlogic
searchlogic copied to clipboard
Multiple arguments breaks IN (?) support in forms
Being able to pass multiple arguments is a great idea for custom named_scopes in the model but IMHO this feature should not be enabled by default on Searchlogic dynamic named_scopes.
I was using Searchlogic with my forms to pass multiple values in a Searchlogic _equals named_scope to create a IN (?) conditions, and since this commit, it is entirely broken.
>> User.state_equals(["refused", "banned", "aborted", "deleted"]).all (This works!) >> User.searchlogic(:state_equals => ["refused", "banned", "aborted", "deleted"]).all /Library/Ruby/Gems/1.8/gems/searchlogic-2.3.9/lib/searchlogic/named_scopes/conditions.rb:117: warning: multiple values for a block parameter (4 for 1) from /Library/Ruby/Gems/1.8/gems/searchlogic-2.3.9/lib/searchlogic/named_scopes/conditions.rb:175 ActiveRecord::PreparedStatementInvalid: wrong number of bind variables (4 for 1) in: users.state IN (?)
I am experiencing the same problem. Using a multi select to pass in possible values to search.
You can define a scope inside your model as a work around.
class MyModel < ActiveRecord::Base
scope_procedure :any_field_eq, lambda { |field_csv| field_eq field_csv.try(:split, ',') }
end
If params[:search][:any_field_eq] = "v1,v2,v3", then you can do User.search(params[:search])