Search query: How to find results across columns

I have created a search box that queries a restaurant database. The
restaurant model is set to search for “name LIKE ?”. However, I
cannot figure out how to add other conditions so that it can also
display “address LIKE ?” and “city LIKE ?”

For example, I want to type in the query “sushi” and find all of the
restaurants that have the name sushi included in them. In this same
box, I would also like to be able to type “oracle rd.” and find all of
the restaurants that have the phrase “oracle rd.” in them.

Essentially, I want to be able to do this in my restaurant model:

def self.search(search)
if search
find(:all, :conditions => [‘name OR address OR city LIKE ?’, “%#
{search}%”])
else
find(:all)
end
end

However, when I do this, it only returns results from the city column.

How can I get my find method to display results for all of these
conditions?

On Jun 18, 11:21 pm, evandrake [email protected] wrote:

However, when I do this, it only returns results from the city column.
your conditions need to end up like “name like ‘foo’ or address like
‘foo’ or city like 'foo;”

Fred

Hi Can do like

find(:all, :conditions => [‘name LIKE ? OR address LIKE ? OR city LIKE
?’, “%#
{search}%”,"%#{search}%","%#{search}%"])

Dont know this can be done any other way

Sijo