I have been tried the following query and it succeeds (only returns the one record with exact match):
def self.search(query)
where("name like ?", query)
end
SQL Executed:
SELECT `products`.* FROM `products` WHERE (name LIKE 'Game')
This query also succeeds (It returns multiple records and there are multiple records with the words ‘Game’ in their name):
def self.search(query)
where("name like ?", "%Game%")
end
SQL Executed:
SELECT `products`.* FROM `products` WHERE (name like '%Game%')
However when I attempt place a wildcard character with interpolation:
def self.search(query)
where("name like ?", "%#{query}%")
end
SQL Executed:
SELECT `products`.* FROM `products` WHERE (name like '%[\"Game\"]%')
It doesn’t return anything. Knowing me…probably missing a comma or something. Thanks in advance…
You are passing an Array instead of a String.
Try:
If it succeeds then fix the query input to be sent as string and not an Array.