Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails activerecord LIKE AND clause error

Here is an activerecord query i'm trying to use in rails

q = "Manchester"
b = "John Smith"

Model.find(:all, :conditions => ["city ? AND name like ?", q, b])

but i get this error in rails console

ActiveRecord::StatementInvalid: SQLite3::SQLException: near "'Manchester'": syntax error: SELECT "model".* FROM "model" WHERE (city 'Manchester' AND name like 'John Smith')

Please help!

like image 743
Matt Jones Avatar asked Dec 05 '22 14:12

Matt Jones


1 Answers

You missed LIKE for city.

Model.where('city LIKE ? AND name LIKE ?', "%#{q}%", "%#{b}%");
like image 144
xdazz Avatar answered Dec 22 '22 15:12

xdazz