My syntax is off. I want to create a scope by_name
that finds all agencies
whose name attribute contains the passed in string (case insensitive).
Here is what I have:
class Agency < ActiveRecord::Base
scope :by_name, ->(agency_name) { where('name ILIKE ?', "%#{agency_name}%") }
end
In the rails console I type in agencies = Agency.by_name("foo")
. Here is the query generated:
SELECT `agencies`.* FROM `agencies` WHERE (name ILIKE '%foo%')
Here is the error message:
Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ILIKE '%foo%')