title: Can Rails search across multiple columns in one query?
body: <p>I wrote a simple search function that just looks for the value in the &quot;name&quot; field. How can I rewrite it if I want to search more fields at the same time?</p>
  <pre><code>&lt;%= form_tag search_tasks_path, :method=&gt; 'get' do %&gt;
          &lt;p&gt;
            &lt;%= text_field_tag :name, params[:name] %&gt;
            &lt;%= submit_tag &quot;Search&quot; , :name=&gt; nil %&gt;
          &lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>
  <p>Can Rails search find plural columns?</p>
  <p><strong>UPDATE</strong>
  I made the following changes to the Controller and View, which caused the search field to become two and the search function to be disabled (only the full data is listed).</p>
  <p>Controller</p>
  <pre><code>  def list
      @tasks = current_user.tasks.order(id: :desc)
    end
  
    def search
      if @tasks = current_user.tasks.where('name=? OR note=?', params[:name], params[:note])
        @tasks = current_user.tasks.order(id: :desc)
      elsif params[:name].present? &amp;&amp; params[:saf].blank?
        @tasks = current_user.tasks.where('name=? and note=?', params[:name], params[:note])
      else
        @tasks = current_user.tasks.order(id: :desc)
      end
  end
  </code></pre>
  <p>View</p>
  <pre><code>&lt;div&gt;
    &lt;%= form_tag search_tasks_path, :method=&gt; 'get' do %&gt;
    &lt;p&gt;
      &lt;%= text_field_tag :name, params[:name] %&gt;
      &lt;%= text_field_tag :note, params[:note] %&gt;
      &lt;%= submit_tag &quot;Search&quot; , :name=&gt; nil %&gt;
    &lt;/p&gt;
    &lt;% end %&gt;
  &lt;/div&gt;
  </code></pre>