title: Convert sql into search for rails 3
body: <p>I have two models which i want to search through my Search form</p>
  
  <pre><code>&lt;%= form_tag({:controller =&gt; 'search', :action =&gt; 'search'}, {:method =&gt; 'get', :remote =&gt; true })  do |select| %&gt;
  &lt;%= label_tag :search, "Enter Keywords Here" %&gt;
  &lt;%= text_field_tag :search, params[:search] %&gt;
  
  &lt;%= label_tag :country, "Search by Country" %&gt;
  &lt;%= collection_select(:country, :country_id, Country.all, :id, :name, :prompt =&gt; 'Please Select') %&gt;
  
  &lt;%= label_tag :difficulty, "Search by Difficulty" %&gt;
  &lt;%= select_tag :difficulty, options_for_select([['Beginner'],['Intermediate'],['Expert']]), {:prompt =&gt; 'Please Select'} %&gt;
  
  &lt;%= label_tag :preperation_time, "Search by preperation time" %&gt;
  &lt;%= select_tag :preperation_time, options_for_select([['15..30'],['30..60'],['60..120']]), {:prompt =&gt; 'Please Select'} %&gt;&lt;br&gt;
  
  &lt;%= submit_tag "Search", :class =&gt; "searchbutton" %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>My understanding is that if I want to be able to search on all the columns my sql statement should look like this</p>
  
  <pre><code>SELECT column dish_name, difficulty, preparation_time FROM Recipe LEFT JOIN Country ON Recipe.dish_name = Country.name AND Recipe.difficulty = Country.name AND Recipe.preparation_time = Country.name
  </code></pre>
  
  <p>this may be totally wrong mind, what i would like to achieve is to be able to search by one parameter or up to all 4</p>
  
  <p>Im not sure how to turn this into rails syntax, currently I have </p>
  
  <pre><code>q = "%#{params[:search]}%"
  @countrysearch = Recipe.includes(:country).where("dish_name LIKE ? OR countries.name LIKE ? OR difficulty LIKE ? OR preperation_time LIKE?", q, q, q,q )
  </code></pre>
  
  <p>If anyone can point me on the right direction that would be much appreciated</p>