title: Search multiple fields with multiple values
body: <p>So what I have is a model <code>Referent</code> that has multiple attributes for example <code>nom</code> and <code>prenom</code>.
  I was able to search each attribute in my model using one search value. But then I tried having one <code>text_field</code> for each attribute so for <code>nom</code> I would have one <code>text_field</code> and for <code>prenom</code> I would have another.</p>
  
  <p>So it would search for all <code>Referent</code> who have that <code>nom</code> and that <code>prenom</code> but I'm not capable of seperating those two search. Right now it just take one of the value and search in both <code>nom</code> and <code>prenom</code> with the same value</p>
  
  <p>View:</p>
  
  <pre><code>&lt;h2&gt;Search Referent&lt;/h2&gt;
  &lt;%= form_tag(referents_path, :method =&gt; "get", id: "search-form") do %&gt;
  &lt;%= text_field_tag :search, params[:search], placeholder: "Nom" %&gt;
  &lt;%= text_field_tag :search, params[:search], placeholder: "Prenom" %&gt;
  &lt;%= submit_tag "Search", class: 'btn btn-info' %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>def index
    @referents = Referent.all
    if params[:search]
      @referents = Referent.search(params[:search]).order("created_at DESC")
    else
      @referents = Referent.all.order("created_at DESC")
    end
  end
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>def self.search(search)
    where("nom || prenom ILIKE ?", "%#{search}%")
  end
  </code></pre>
  
  <p>Right now it just seems to take the value of the second <code>text_field</code> and use that for the search. I'm using postgresql.</p>
  
  <p>The full view:</p>
  
  <pre><code>&lt;div class="container"&gt;
  &lt;h2&gt;Search Referent&lt;/h2&gt;
  &lt;%= form_tag(referents_path, :method =&gt; "get", id: "search-form") do %&gt;
  &lt;%= text_field_tag :search_nom, params[:search], placeholder: "Nom" %&gt;
  &lt;%= text_field_tag :search_prenom, params[:search], placeholder: "Prenom" %&gt;
  &lt;%= submit_tag "Search", class: 'btn btn-info' %&gt;
  &lt;% end %&gt;
  
  &lt;h2&gt;List de Referent&lt;/h2&gt;
  
  &lt;table class="table table-hover"&gt;
    &lt;tr&gt;
      &lt;th&gt;Nom&lt;/th&gt;
      &lt;th&gt;Prenom&lt;/th&gt;
      &lt;th&gt;Titre&lt;/th&gt;
      &lt;th&gt;Departement&lt;/th&gt;
      &lt;th&gt;Cellulaire&lt;/th&gt;
      &lt;th&gt;Bureau&lt;/th&gt;
      &lt;th&gt;Fax&lt;/th&gt;
      &lt;th&gt;Courriel&lt;/th&gt;
      &lt;th&gt;Organisme Referent&lt;/th&gt;
    &lt;/tr&gt;
    &lt;% @referents.each do |referent| %&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;%= referent.nom %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= referent.prenom %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= referent.titre %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= referent.departement %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= referent.cellulaire %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= referent.bureau %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= referent.fax %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= referent.courriel %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= link_to referent.organismereferent.nom_organisation, organismereferent_path(referent.organismereferent_id) %&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;% end %&gt;
  &lt;/table&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>Error using Ramon answer<a href="https://i.stack.imgur.com/ZfP8p.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZfP8p.png" alt="enter image description here"></a></p>