Two questions:
-How can I count words in a variable string?
“How can I count words in a variable string?”.split(/\s+/).length # => 9
and -I have a variable, such a, string=“INN SO”. How can I found this string in mysql database where the field is “DINNER, SOAP”, for exemple?
search_params = “INN SO”
search_conditions = search_params.split(/\s+/).map{|s| “name LIKE ‘%#{s}%’” }.join(" AND ") # => “name LIKE ‘%INN%’ AND name LIKE ‘%SO%’”
Product.find(:all, :conditions => search_conditions)