Sha256: a7686d7a7b4ca8e4781b494ffe015eed2d09dc373da73a1a6cad8b0b485ae050

Contents?: true

Size: 447 Bytes

Versions: 1

Compression:

Stored size: 447 Bytes

Contents

if defined?(ActiveRecord)
  module ServiceTemplate
    module SortableApi
      def sort_from_params(objects, sort_params)
        return objects if sort_params.nil?

        sort_fields = sort_params.split(",")
        sort_fields.each do |sort_field|
          sort_field = (sort_field[1..-1] + " DESC") if sort_field.start_with?("-")
          objects = objects.order(sort_field)
        end

        return objects
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
service_template-0.5.0 lib/service_template/sortable_api.rb