title: How to remove empty parameters from params hash?
body: <p>In my Rails 4 application I have this setup:    </p>
  
  <pre><code>class InvoicesController &lt; ApplicationController
  
    def index
      @invoices = current_user.invoices.search(params)
    end
  
    ...
  
  end
  </code></pre>
  
  <hr>
  
  <pre><code>class Invoice &lt; ActiveRecord::Base
  
    belongs_to :user
  
    def self.search(params)
      data = all
      data = data.where("number LIKE ?", "%#{params[:number]}%") if params[:number]
      data = data.where("total &gt; ?", params[:minimum]) if params[:minimum]
      data = data.where("total &lt; ?", params[:maximum]) if params[:maximum]
      data
    end
  
    ...
  
  end
  </code></pre>
  
  <p>The problem is that I have a bunch of other GET parameters which are all part of the <code>params</code> hash. How can I remove the blank parameters from the URL so that I don't end up with URLs like:</p>
  
  <pre><code>/invoices?after=&amp;before=&amp;maximum=&amp;minimum=&amp;number=
  </code></pre>
  
  <p>Thanks for any help.</p>