Ransack attribute/predicate/value style search – passing in multiple conditions as an array?

I’m trying to implement a railscast-style multiple conditions search using the Ransack and having some difficult using multiple selects as values for the an attribute/predicate/value style search.

The crux of this issue seems to be the below code. Try as I might, I’m struggling to pass in multiple conditions. Is there any way I can do so using this methodology?

If this isn’t possible, could you suggest a workaround or alternative methodology?

q = {"c"=>{"0"=>{"a"=>{"0"=>{"name"=>"role_type_id"}}, "p"=>"in", "v"=>{"0"=>{"value"=>[5, 6]}}}}}
reload!; @q = StaffMember.ransack(q).result.count

NoMethodError: undefined method 'to_i' for [5, 6]:Array from /Users/sig/.rvm/gems/ruby-1.9.3-p484@sense-r4/gems/ransack-1.6.6/lib/ransack/nodes/value.rb:81:in 'cast_to_integer' from /Users/sig/.rvm/gems/ruby-1.9.3-p484@sense-r4/gems/ransack-1.6.6/lib/ransack/nodes/value.rb:34:in 'cast' from /Users/sig/.rvm/gems/ruby-1.9.3-p484@sense-r4/gems/ransack-1.6.6/lib/ransack/predicate.rb:74:in 'block in validate' from /Users/sig/.rvm/gems/ruby-1.9.3-p484@sense-r4/gems/ransack-1.6.6/lib/ransack/predicate.rb:74:in 'each' from /Users/sig/.rvm/gems/ruby-1.9.3-p484@sense-r4/gems/ransack-1.6.6/lib/ransack/predicate.rb:74:in 'any?' from /Users/sig/.rvm/gems/ruby-1.9.3-p484@sense-r4/gems/ransack-1.6.6/lib/ransack/predicate.rb:74:in 'validate' from /Users/sig/.rvm/gems/ruby-1.9.3-p484@sense-r4/gems/ransack-1.6.6/lib/ransack/nodes/condition.rb:48:in 'valid?' from /Users/sig/.rvm/gems/ruby-1.9.3-p484@sense-r4/gems/ransack-1.6.6/lib/ransack/nodes/grouping.rb:44:in 'block in conditions=' from /Users/sig/.rvm/gems/ruby-1.9.3-p484@sense-r4/gems/ransack-1.6.6/lib/ransack/nodes/grouping.rb:42:in 'each' from /Users/sig/.rvm/gems/ruby-1.9.3-p484@sense-r4/gems/ransack-1.6.6/lib/ransack/nodes/grouping.rb:42:in 'conditions=' from /Users/sig/.rvm/gems/ruby-1.9.3-p484@sense-r4/gems/ransack-1.6.6/lib/ransack/search.rb:51:in 'block in build' from /Users/sig/.rvm/gems/ruby-1.9.3-p484@sense-r4/gems/ransack-1.6.6/lib/ransack/search.rb:47:in 'each' from /Users/sig/.rvm/gems/ruby-1.9.3-p484@sense-r4/gems/ransack-1.6.6/lib/ransack/search.rb:47:in 'build' from /Users/sig/.rvm/gems/ruby-1.9.3-p484@sense-r4/gems/ransack-1.6.6/lib/ransack/search.rb:39:in 'initialize' from /Users/sig/.rvm/gems/ruby-1.9.3-p484@sense-r4/gems/ransack-1.6.6/lib/ransack/adapters/active_record/base.rb:15:in 'new' from /Users/sig/.rvm/gems/ruby-1.9.3-p484@sense-r4/gems/ransack-1.6.6/lib/ransack/adapters/active_record/base.rb:15:in 'ransack' from (irb):421 from /Users/sig/.rvm/gems/ruby-1.9.3-p484@sense-r4/gems/railties-4.2.1/lib/rails/commands/console.rb:110:in 'start' from /Users/sig/.rvm/gems/ruby-1.9.3-p484@sense-r4/gems/railties-4.2.1/lib/rails/commands/console.rb:9:in 'start' from /Users/sig/.rvm/gems/ruby-1.9.3-p484@sense-r4/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:68:in 'console' from /Users/sig/.rvm/gems/ruby-1.9.3-p484@sense-r4/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:39:in 'run_command!' from /Users/sig/.rvm/gems/ruby-1.9.3-p484@sense-r4/gems/railties-4.2.1/lib/rails/commands.rb:17:in '<top (required)>' from script/rails:6:in 'require' from script/rails:6:in '<main>'


Source: ruby

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.