Like clause for find

I’ve done a bit of searching, but got too much noise and no
perceivable signal. So, I apologize if I’m just missing this in the
docs, seems like it should be easy.

I’d like to provide some basic search functionality in my app by
allowing the user to enter in some text and generating a query like
so:

SELECT * FROM things WHERE field LIKE ‘%input’%;

If I want to do this am I stuck with find_by_sql, or is there a way to
do this with a :conditions option?

Thanks,

pt.

Parker T.
http://www.parkert.com/
510.541.0125

Parker T. wrote:

If I want to do this am I stuck with find_by_sql, or is there a way to
do this with a :conditions option?

You can use conditions:

Thing.find(:all, :conditions => [‘field LIKE ?’, ‘%input%’])

Phil


Philip R.
http://tzinfo.rubyforge.org/ – DST-aware timezone library for Ruby