ruby on rails 3 - ActiveRecord search model using LIKE only returning exact matches -


in rails app trying search users model based on conditions.

in particular, have location field string , want search field based on whether contains search string. example, if search users location 'oxford' want return users variation on that, 'oxford, england'.

having searched web answer seems should using keyword in activerecord search, me returning exact matches.

here snippet of code search method

conditions_array = [] conditions_array << [ 'lower(location) ?', options[:location].downcase ] if !options[:location].empty? conditions = build_search_conditions(conditions_array) results = user.where(conditions) 

am doing wrong? or using not right approach achieving objective?

you need like '%oxford%'

% matches number of characters, 0 characters

conditions_array << [ 'lower(location) ?', "%#{options[:location].downcase}%" ] if !options[:location].empty? 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -