title: How to add validation if search is empty?
body: <p>I am trying to add a search functionality to my ruby on rails application. The search works fine but how can I add a validation so it displays when the search is empty?</p>
  
  <p>I have tried adding <code>required: true</code> but that doesn't seem to do much. </p>
  
  <p>index.html.erb:</p>
  
  <pre><code>&lt;%= form_tag topics_path, :method =&gt; 'get' do %&gt;
    &lt;%= text_field_tag :search, params[:search], required: true %&gt;
    &lt;%= submit_tag "Search" %&gt;   
  &lt;% end %
  </code></pre>
  
  <p>topics_controller:</p>
  
  <pre><code>def index
  @topics = Topic.search(params[:search]).paginate(:page =&gt; params[:page], :per_page =&gt; 5)
  end
  </code></pre>
  
  <p>topics.rb</p>
  
  <pre><code>def self.search(search)
          if search 
              where(["title LIKE ?","%#{search}%"])
          else
          all 
      end
  </code></pre>
  
  <p>I expect the output to be:
  1. Search for particular topic
  2. There is no topics within that field so a validation is displayed such as "no results found, please try again"</p>