create params[:q] condition with "in" predicate #175

Closed
lironbeni opened this Issue Dec 12, 2012 · 1 comment

Comments

Projects
None yet
2 participants
@lironbeni

Hi Ernie,

What I'm trying to do is to create params[:q] condition with "in" predicate that produces the following SQL code:
SELECTcell_lines.* FROMcell_linesWHEREcell_lines.idIN (9,10)

I'm inserting this to the params[:q]:
{"c"=>{"0"=>{"v"=>{"0"=>{"value"=>[9,10]}}, "p"=>"in", "a"=>{"0"=>{"name"=>"id"}}}}}

And getting the following error:

NoMethodError: undefined method `to_i' for [9, 10]:Array
from /.rvm/gems/ruby-1.8.7-p358@187-biokm/gems/ransack-0.7.0/lib/ransack/nodes/value.rb:82:in `cast_to_integer'
  from /.rvm/gems/ruby-1.8.7-p358@187-biokm/gems/ransack-0.7.0/lib/ransack/nodes/value.rb:35:in `cast'
  from /.rvm/gems/ruby-1.8.7-p358@187-biokm/gems/ransack-0.7.0/lib/ransack/predicate.rb:66:in `validate'
  from /.rvm/gems/ruby-1.8.7-p358@187-biokm/gems/ransack-0.7.0/lib/ransack/predicate.rb:66:in `select'
  from /.rvm/gems/ruby-1.8.7-p358@187-biokm/gems/ransack-0.7.0/lib/ransack/predicate.rb:66:in `validate'
  from /.rvm/gems/ruby-1.8.7-p358@187-biokm/gems/ransack-0.7.0/lib/ransack/nodes/condition.rb:40:in `valid?'
  from /.rvm/gems/ruby-1.8.7-p358@187-biokm/gems/ransack-0.7.0/lib/ransack/nodes/grouping.rb:42:in `c='
  from /.rvm/gems/ruby-1.8.7-p358@187-biokm/gems/ransack-0.7.0/lib/ransack/nodes/grouping.rb:40:in `each'
  from /.rvm/gems/ruby-1.8.7-p358@187-biokm/gems/ransack-0.7.0/lib/ransack/nodes/grouping.rb:40:in `c='
  from /.rvm/gems/ruby-1.8.7-p358@187-biokm/gems/ransack-0.7.0/lib/ransack/search.rb:34:in `send'
  from /.rvm/gems/ruby-1.8.7-p358@187-biokm/gems/ransack-0.7.0/lib/ransack/search.rb:34:in `build'
  from /.rvm/gems/ruby-1.8.7-p358@187-biokm/gems/ransack-0.7.0/lib/ransack/search.rb:29:in `each'
  from /.rvm/gems/ruby-1.8.7-p358@187-biokm/gems/ransack-0.7.0/lib/ransack/search.rb:29:in `build'
  from /.rvm/gems/ruby-1.8.7-p358@187-biokm/gems/ransack-0.7.0/lib/ransack/search.rb:21:in `initialize'
  from /.rvm/gems/ruby-1.8.7-p358@187-biokm/gems/ransack-0.7.0/lib/ransack/adapters/active_record/base.rb:15:in `new'
  from /.rvm/gems/ruby-1.8.7-p358@187-biokm/gems/ransack-0.7.0/lib/ransack/adapters/active_record/base.rb:15:in `ransack'

actually what I'm asking is how do I convert this:
params[:q] = {"id_in" => [9,10]}
into this:
params[:q] = {"c"=>{"0"=>{"v"=>{"0"=>{"value"=>[9,10]}}, "p"=>"in", "a"=>{"0"=>{"name"=>"id"}}}}}
so they will work the same...

Would really appreciate your help in this manner

@seanfcarroll

This comment has been minimized.

Show comment Hide comment
@seanfcarroll

seanfcarroll May 24, 2017

Member

This issue appears more to be a HOW-TO issue rather than a bug in Ransack. We are in the process of cleaning up the Ransack gem and repo. If this issue is still relevant could you please ask it on StackOverflow?

If you think it is an issue with Ransack, please provide a repo with the issue and / or a pull request with failing tests. If you don't know how to do this, indicate it in the issue and we will look into it eventually.

Thank you

https://github.com/activerecord-hackery/ransack/blob/master/CONTRIBUTING.md

#794

Member

seanfcarroll commented May 24, 2017

This issue appears more to be a HOW-TO issue rather than a bug in Ransack. We are in the process of cleaning up the Ransack gem and repo. If this issue is still relevant could you please ask it on StackOverflow?

If you think it is an issue with Ransack, please provide a repo with the issue and / or a pull request with failing tests. If you don't know how to do this, indicate it in the issue and we will look into it eventually.

Thank you

https://github.com/activerecord-hackery/ransack/blob/master/CONTRIBUTING.md

#794

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment