0

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

Rutger
  • 185
  • 2
  • 11

1 Answers1

2

replace

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

with

conditions=Hash[{:attr1 => 450} | {:attr2 => 450}, :lang => 2]
alexkv
  • 5,144
  • 2
  • 21
  • 18
  • Alex,Argh, sorry that was i typoe in my code above (I adjusted it). In the real code that bracket was not there so thanks for the tip but not a solution to my problem – Rutger May 30 '12 at 07:49
  • So, you still have error `unexpected tASSOC, expecting ']` even without that bracket? – alexkv May 30 '12 at 07:54
  • By the way, try this condition `conditions = [{:attr1 => 450} | {:attr2 => 450}, :lang => 2]` – alexkv May 30 '12 at 07:55