ruby on rails 3 - How to specify multiple values in where with AR query interface in rails3 -


per section 2.2 of rails guide on active record query interface here:

which seems indicate can pass string specifying condition(s), array of values should substituted @ point while arel being built. i've got statement generates conditions string, can varying number of attributes chained either , or or between them, , pass in array second arg method, , get:

activerecord::preparedstatementinvalid: wrong number of bind variables (1 5)

which leads me believe i'm doing incorrectly. however, i'm not finding on how correctly. restate problem way, need pass in string method such "table.attribute = ? , table.attribute1 = ? or table.attribute1 = ?" unknown number of these conditions anded or ored together, , pass something, thought array second argument used substitute values in first argument conditions string. correct approach, or, i'm missing other huge concept somewhere , i'm coming @ wrong? i'd think somehow, has possible, short of generating raw sql string.

sounds you're doing this:

model.where("attribute = ? or attribute2 = ?", [value, value]) 

whereas need this:

# notice lack of array last argument model.where("attribute = ? or attribute2 = ?", value, value) 

have @ http://guides.rubyonrails.org/active_record_querying.html#array-conditions more details on how works.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -