From: Gavin Kistner Date: 2004-10-27T11:58:12+09:00 Subject: Re: [ANN] New RubyGarden article: "Reflections on Rails" Great article! One comment: > def search > terms = @params['search']['terms'].scan(/"(.*?)"|([^"\s]+)/). > flatten.compact > cond = "body LIKE '%#{terms[0]}%' " > cond << terms[1..-1].map {|t| " AND body LIKE '%#{t}%'"}.join("") > @results = Entry.find_all(cond) > end > > But most of the scrappiness has to do with the piecing together of the > SQL condition. Once all that is in place, the last line of the method > body does everything that�s needed to prepare the environment for the > view. (Note: readers are invited to send me ideas for cleaner ways to > generate that multiple condition line!) For the one bit I unerstand, how about: def search terms = @params['search']['terms'].scan(/"(.*?)"|([^"\s]+)/).flatten.compact @results = Entry.find_all terms.map{ |t| "body LIKE '%#{t}%'" }.join( ' AND ' ) end