EffeBi EffeBi - 3 months ago 11
Ruby Question

RoR - Active record query with exact match and 'LIKE'

i need to build a ActiveRecord query in RoR environment, with 'exact match' and 'LIKE' as 'Where' params.

this is an example:

@find = Person.where(name: @f_name, surname: @f_surname, address: @f_address)


in the exaple, name and surname are exact match, but address must be something like "like %@f_address%", but ii can't goal it !!!

i tried also

@find = Person.where('name LIKE ? and surname LIKE ? and address LIKE ?', @f_name, @f_surname, '%#{@f_address}%')


But the result is the same!

Can someone help me?
Thanks!

Answer

I think the only issue is that you need double quote for interpolation. Try

"%#{@f_address}%"
Comments