ruby on rails - can you use activerecord to find substring of a field? (quick & dirty keyword finder) -


suppose database contains field 'keywords' , sample records include: "pipe wrench" "monkey wrench" "crescent wrench" "crescent roll" "monkey bars"

is there way in activerecord find records keyword field contains substring "crescent"?

(it's quick , dirty lookup quick concept prototype)

yeah, use statement in mysql.

in rails 2.x:

table.find(:all, :conditions => ['keywords ?', '%crescent%']) 

in rails 3.x:

table.where('keywords ?', '%crescent%').all 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -