let\'s say I have a string in which the words are separated by 1 or more spaces and I want to use that string in and SQL LIKE condition. How do I make my SQL and tell it to
I just replace the whitespace chars with '%'. Lets say I want to do a LIKE query on a string like this 'I want to query this string with a LIKE'
@search_string = 'I want to query this string with a LIKE'
@search_string = ("%"+@search_string+"%").tr(" ", "%")
@my_query = MyTable.find(:all, :conditions => ['my_column LIKE ?', @search_string])
first I add the '%' to the start and end of string with
("%"+@search_string+"%")
and then replace other remaining whitespace chars with '%' like so
.tr(" ", "%")