Forum: Ruby on Rails like clause for find

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
19c9af375aca3001e3978cb16684803c?d=identicon&s=25 Parker Thompson (Guest)
on 2006-01-29 00:07
(Received via mailing list)
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 Thompson
http://www.parkert.com/
510.541.0125
9ab183bb240ffd3a3966d5a615b4bdeb?d=identicon&s=25 Philip Ross (Guest)
on 2006-01-29 00:31
(Received via mailing list)
Parker Thompson 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 Ross
http://tzinfo.rubyforge.org/ -- DST-aware timezone library for Ruby
This topic is locked and can not be replied to.