title: Rails 3 Searching through a string using an array
body: <p>I am attempting to do a search in Rails 3 like so.  I have a database object like so with an attribute like so:</p>
  
  <pre><code>@food.fruit = "Apples, Pears, Plums"
  </code></pre>
  
  <p>and I have a search that uses params from a checkbox, like so:</p>
  
  <pre><code>params[:search] = ["Apples", "Oranges", "Bananas", "Grapefruit"]
  </code></pre>
  
  <p>Since my <code>@food</code> object above has "Apples" and the search array has "Apples" I'd like for this search to be successful.  However I am having trouble having this work properly.</p>
  
  <p>My initial thought was to do something like</p>
  
  <pre><code>@results = Food.where("fruit LIKE ?", "%params[:search]%")
  </code></pre>
  
  <p>or</p>
  
  <pre><code>@results = Food.where("fruit IN ?", params[:search])
  </code></pre>
  
  <p>But the first only works if the <code>params[:search]</code> contains ONLY the <code>@food.fruit</code> elements and no others. The second doesn't work at all.</p>
  
  <p>My last ditch resort is to do something like</p>
  
  <pre><code>@results = Array.new
  params[:search].each do |search|
    @results &lt;&lt; Food.where("fruit LIKE ?", search)
  end
  </code></pre>
  
  <p>but I'd rather not do that if I don't have to.  Anyone have any advice? </p>