To verify that the query string is cleared correctly, use array or hash syntax to describe your conditions:
Foo.where("bar LIKE ?", "%#{query}%")
or
Foo.where("bar LIKE :query", query: "%#{query}%")
If it is possible that query may contain the % character, then you need to sanitize the query with sanitize_sql_like first:
Foo.where("bar LIKE ?", "%#{sanitize_sql_like(query)}%") Foo.where("bar LIKE :query", query: "%#{sanitize_sql_like(query)}%")
spickermann Sep 29 '14 at 7:27 2014-09-29 07:27
source share