Searching multiple fields in table using LIKE

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

conditions = [“first_name LIKE ? OR email like ?”,
“%#{@params[:query]}%”,
“%#{@params[:query]}%”] etc.

Vish

I’m not having luck with that suggestion. I’m getting the following
error:

parse error, unexpected $, expecting kEND

David

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs