سؤال

I'm using the Metawhere rails gem to query my dbase. I have a query that works:

t=Model.where({:attr1 => 450} | {:attr2 => 450}, :lang => 2)

now I trying to abstract the conditions from the query like this:

conditions=Hash[{:attr1 => 450} | {:attr2 => 450}, :lang => 2]
t=Model.where(conditions)

but the first line gives me: syntax error, unexpected tASSOC, expecting ']

I tried a lot of things like making the conditions a string and eval(conditions) in the query. but that gives me SyntaxError: (eval):1:in `irb_binding': compile error (eval):1: syntax error, unexpected ',', expecting $end

I'm stuck. If you can help me that would be appreciated.

Rutger

هل كانت مفيدة؟

المحلول

replace

conditions=Hash[{:attr1 => 450} | {:attr2 => 450}, :lang => 2}]

with

conditions=Hash[{:attr1 => 450} | {:attr2 => 450}, :lang => 2]
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top