drlelon
1
Hi,
How can I expand the following conditions:
conditions = [“first_name LIKE ?”, “%#{@params[:query]}%”]
to be able to search in other fields in the same database table?
I want to be able to run a query using the same query string, but search
multiple columns such as first_name, email, and comments.
The SQL would be:
SELECT first_name, email, comments FROM contacts WHERE first_name LIKE
“string” OR email LIKE “string” OR comments LIKE “string”
Thanks,
David
drlelon
2
conditions = [“first_name LIKE ? OR email like ?”,
“%#{@params[:query]}%”,
“%#{@params[:query]}%”] etc.
Vish
drlelon
3
I’m not having luck with that suggestion. I’m getting the following
error:
parse error, unexpected $, expecting kEND
David
drlelon
4
Check your source. You’ve probably got an unclosed begin end block
somewhere
(syntax error). The way it should work is this:
Model.find(:all, :conditions => [‘id = ? OR id = ?’, id1, id2])
(the example in my previous mail should read ‘:conditions =>’ instead of
‘:conditions =’)
Vish