In Ruby (or Rails) we can do
new_params = params.merge({:order => 'asc'})
and is now new_paramsa hash with an added key :order.
But is there a line returning a hash with the remote key? Line
new_params = params.delete(:order)
will not work because the method deletereturns a value and its value. Should we do this in 3 steps?
tmp_params = params
tmp_params.delete(:order)
return tmp_params
Is there a better way? Because I want to do
new_params = (params[:order].blank? || params[:order] == 'desc') ?
params.merge({:order => 'asc') :
(foo = params; foo.delete(:order); foo)
but the last line above is somewhat awkward. Is there a better way to do this?
( : - "desc", , order, , desc, order=asc, order, desc)