Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple where conditions in Rails

I'm implementing a user search feature in my Rails app. However, I don't want admins to appear in the search results.

I'm trying this:

User.where(:admin => [nil, false], ["name LIKE ?", "%#{params[:query]}%"])

But I get this error:

syntax error, unexpected ')', expecting tASSOC

So how do I properly list where clauses inside the parentheses?

like image 388
XåpplI'-I0llwlg'I - Avatar asked Feb 25 '13 05:02

XåpplI'-I0llwlg'I -


1 Answers

Try this

User.where(["name LIKE ?", "%#{params[:query]}%"]).where(:admin => [nil, false])
like image 156
Ismael Avatar answered Oct 24 '22 15:10

Ismael