app/controllers/concerns/orderable.rb
# A list of the param names that can be used for ordering the model list
A list of the param names that can be used for ordering the model list
A list of the param names that can be used for ordering the model list
def ordering_params(params)
    ordering = {}
    if params[:sort]
      sort_order = { '-' => :asc, '+' => :desc }
      sorted_params = params[:sort].split(',')
      sorted_params.each do |attr|
        sort_sign = attr.match?(/\A[+-]/) ? attr.slice!(0) : '+'
        model = controller_name.classify.constantize
        if model.attribute_names.include?(attr)
          ordering[attr] = sort_order[sort_sign]
        end
      end
    end
    ordering
  end
def ordering_params ( params ) ordering = { } if params [ :sort ] sort_order = { '-' => :asc , '+' => :desc } sorted_params = params [ :sort ] . split ( ',' ) sorted_params . each do | attr | sort_sign = attr . match? ( / \A [+-] / ) ? attr . slice! ( 0 ) : '+' model = controller_name . classify . constantize if model . attribute_names . include? ( attr ) ordering [ attr ] = sort_order [ sort_sign ] end end end ordering end
A list of the param names that can be used for ordering the model list
A list of the param names that can be used for ordering the model list
params
<not_specific>