Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use LIKE query in Ruby on Rails

LIKE query in mysql, queries the database and disregards case. For example:

"bzupnick" = "Bzupnick" #  false
"bzupnick" LIKE "Bzupnick" # true

So how does one do a LIKE query in Ruby on Rails.

Here's an example query:

@results = User.joins(:jobs).where(:jobs => { :job_name => job }, :users => { :zip => zip })
like image 456
bzupnick Avatar asked Jan 13 '23 13:01

bzupnick


1 Answers

try this..

User.joins(:job).where("job_name like ? and name like ?","%Dummy%", "%Bzupnick")

You can also verfify the SQL query by putting to_sql at the end of the above statement

like image 102
Aditya Kapoor Avatar answered Jan 17 '23 15:01

Aditya Kapoor