What's the easiest way to do a quick wildcard search on a field from the console? I don't care against guarding against SQL injection.
I'm using PostgreSQL.
Searching for title
with strings containing "emerging'
This works but is somewhat cumbersome. Curious if there was a shorthand?
Product.where("title @@ :q", q: "emerging")
Equally cumbersome but no longer appear to work for me in Rails 4:
Product.where("title ILIKE ?", "emerging")
Product.where("title ilike :q", q: "emerging")
I guess I'm looking for something like Product.where(title: "*emerging*")
This should do it:
word = 'emerging'
Product.where('title ILIKE ?', "%#{word}%")
Use LIKE
, like this:
Product.where('title LIKE ?', '%emerging%')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With