title: Conditions with Bind Variables and Optional Parameters
body: <p>Let's say I have a form where users can search for people whose name starts with a particular <code>name</code> string, for example, "Mi" would find "Mike" and "Miguel". I would probably create a find statement like so:</p>
  
  <pre><code>find(:all, :conditions =&gt; ['name LIKE ?', "#{name}%"])
  </code></pre>
  
  <p>Let's say the form also has two optional fields, <code>hair_color</code> and <code>eye_color</code> that can be used to further filter the results. Ignoring the name portion of the query, a find statement for people that can take in an arbitrary number of optional parameters might look like this:</p>
  
  <p><code>find(:all, :conditions =&gt; { params[:person] })</code></p>
  
  <p>Which for my two optional parameters would behave as the equivalent of this:</p>
  
  <p><code>find(:all, :conditions =&gt; { :hair_color =&gt; hair_color, :eye_color =&gt; eye_color })</code></p>
  
  <p>What I can't figure out is how to merge these two kinds of queries where the required field, "name" is applied to the "like" condition above, and the optional <code>hair_color</code> and <code>eye_color</code> parameters (and perhaps others) can be added to further filter the results.</p>
  
  <p>I certainly can build up a query string to do this, but I feel there must be a "rails way" that is more elegant. How can I merge mandatory bind parameters with optional parameters?</p>