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)
The Postgres database syntax would be:
Yeah, just use a LIKE statement in MySQL.
In Rails 2.x:
In Rails 3.x:
It all depends on your DB. Is it Postgres? MySQL? MongoDB? Anything else?
With Postgres, you could use something like :
You just have to find the right syntax for your DB / Rails / ActiveRecord version.
I had a similar issue. I needed to see if there are keywords passed from conrolled input in the frontend component in the body of any questions in my questions table. Here is how I did it in my controller: