app/controllers/breweries_controller.rb
def order_params
    return unless params[:sort]

    ordering = {}
    sorted_params = params[:sort].split(',')

    sorted_params.each do |attr|
      attr, sort_m = attr.split(':')
      sort_method = SORT_ORDER.include?(sort_m) ? sort_m : 'asc'
      attr = 'brewery_type' if attr == 'type'

      ordering[attr] = sort_method.to_sym if Brewery.attribute_names.include?(attr)
    end

    ordering
  end
# A list of the param names that can be used for ordering the model list.
# For example it retrieves a list of breweries in descending order of type.
# Within a specific type, names are ordered first
# order_params
# GET /breweries?sort=type_desc,name
# order_params # => { brewery_type: :desc, name: :asc }
# Brewery.order(brewery_type: :desc, name: :asc)
#
A list of the param names that can be used for ordering the model list.
For example it retrieves a list of breweries in descending order of type.
A list of the param names that can be used for ordering the model list . For example it retrieves a list of breweries in descending order of type .
def order_params
    return unless params[:sort]
    ordering = {}
    sorted_params = params[:sort].split(',')
    sorted_params.each do |attr|
      attr, sort_m = attr.split(':')
      sort_method = SORT_ORDER.include?(sort_m) ? sort_m : 'asc'
      attr = 'brewery_type' if attr == 'type'
      ordering[attr] = sort_method.to_sym if Brewery.attribute_names.include?(attr)
    end
    ordering
  end
def order_params return unless params [ :sort ] ordering = { } sorted_params = params [ :sort ] . split ( ',' ) sorted_params . each do | attr | attr , sort_m = attr . split ( ':' ) sort_method = SORT_ORDER . include? ( sort_m ) ? sort_m : 'asc' attr = 'brewery_type' if attr == 'type' ordering [ attr ] = sort_method . to_sym if Brewery . attribute_names . include? ( attr ) 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 .