Two questions: -How can I count words in a variable string? 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? Thank you, Diego -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 5/28/07, Diego Muñoz <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > 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) -- Scott Becker Electro Interactive, Inc. Office: 813-333-5508 http://ElectroInteractive.com <http://electrointeractive.com/> http://sbecker.net --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Scott Becker wrote:> On 5/28/07, Diego Muñoz <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:>> -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) >Thanks Scott for your answer, but the solution for my question is in <http://www.ruby-forum.com/topic/109645#new> Diego -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---