Suppose a database contains a field 'keywords' and sample records include: "pipe wrench" "monkey wrench" "crescent wrench" "crescent roll" "monkey bars"
is there a way in activerecord to find the records where the keyword field contains the substring "crescent"?
(It's just a quick and dirty lookup for a quick concept prototype)
Yeah, just use a LIKE statement in MySQL.
In Rails 2.x:
Table.find(:all, :conditions => ['keywords LIKE ?', '%crescent%'])
In Rails 3.x:
Table.where('keywords LIKE ?', '%crescent%').all
2.1m questions
2.1m answers
60 comments
57.0k users