[Rails] Re: Simple Search
Jean-François
jf.web3 at gmail.com
Mon Apr 10 00:54:26 GMT 2006
Hello Adam,
> Those methods are a good start, but there's a problem. :) I have a lot
> of categories, which is why I want a search for them. I need the search
> to match similar names as well as exact; so searching for "insurance"
> finds "investment and insurance."
>
> That's why I mentioned I thought it would involve MySQLs "LIKE"
> command. I realize I could write a find_by_sql instruction that would
> probably work, but if there's a cleaner more Rails-y way to do it I'd like
> to try that.
Try :
@categories = Category.find :all,
:conditions => ['name LIKE ?', "%#{params[:find_category]}%" ]
Good night,
-- Jean-François.
--
À la renverse.
More information about the Rails
mailing list