title: How do I stop a flash error message from showing on page load until after button is clicked in ruby on rails?
body: <p>I'm trying to figure out a way to stop this flash message from showing on page load:</p>
  
  <pre><code>class SearchesController &lt; ApplicationController
  
     def index
  
       @users = User.search params[:search]
       @default_image = "/assets/default_avatar.jpg"
       if @users.empty? || params[:search].blank? 
          flash[:error] = "Sorry no user(s) found!" if @users.empty?
          flash[:error] = "Please give us something to search for!" if params[:search].blank?
          render 'index'
       end    
     end
  end
  </code></pre>
  
  <p>I understand why it's showing (obviously when page is visited the search params is blank already). There must be some trick in ruby on rails that I can use on this flash message to stop it from firing until search button is clicked e.g.</p>
  
  <pre><code>flash[:error] = "Please give us something to search for!" if params[:search].blank? after_get 
  </code></pre>
  
  <p>Bare in mind that was after_get was made up.</p>
  
  <p>I'm sure someone out there has the answer for this.</p>
  
  <p>I saw after_commit in the rails api but no example of how to use it in my situation or even if it's what I need.</p>
  
  <p>Kind reards</p>