In my Rails 4 application, I have this setting:
class InvoicesController < ApplicationController def index @invoices = current_user.invoices.search(params) end ... end
class Invoice < 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 > ?", params[:minimum]) if params[:minimum] data = data.where("total < ?", params[:maximum]) if params[:maximum] data end ... end
The problem is that I have many other GET parameters that are part of the params hash. How can I remove empty parameters from a URL so that I don't have URLs like:
/invoices?after=&before=&maximum=&minimum=&number=
Thanks for any help.
ruby ruby-on-rails activerecord
Tintin81
source share