app/controllers/application_controller.rb
# Sorts given active record objects thing by the given paramaters. 
Sorts given active record objects thing by the given paramaters.
Sorts given active record objects thing by the given paramaters .
def sort_results(params, objects)
      return objects if objects.blank?
      @order = params[:order]
      @current_order = params[:current_order]
      @ascending = params[:ascending]
      @table = params[:table]
      @ascending = 'true' if @ascending.blank?
      unless @order.blank?
        objects = objects.eager_load(@table) unless @table.blank?
        if @ascending == 'true' && (@current_order == @order || @current_order.blank?)
          objects = objects.order(@order).reverse_order
          @ascending = 'false'
        else
          objects = objects.order(@order)
          @ascending = 'true'
        end
      else
        if objects.first.respond_to?(:name)
          objects = objects.order(:name)
         else
          objects = objects.order(:last_name, :first_name)
        end
      end 
      return objects
    end
def sort_results ( params , objects ) return objects if objects . blank? @order = params [ :order ] @current_order = params [ :current_order ] @ascending = params [ :ascending ] @table = params [ :table ] @ascending = 'true' if @ascending . blank? unless @order . blank? objects = objects . eager_load ( @table ) unless @table . blank? if @ascending == 'true' && ( @current_order == @order || @current_order . blank? ) objects = objects . order ( @order ) . reverse_order @ascending = 'false' else objects = objects . order ( @order ) @ascending = 'true' end else if objects . first . respond_to? ( :name ) objects = objects . order ( :name ) else objects = objects . order ( :last_name , :first_name ) end end return objects end
Sorts given active record objects thing by the given paramaters.
Sorts given active record objects thing by the given paramaters .
# Because whatever is returned will be paginated, it has to still be an activerecord relation. # That is why we return blank objects instead of nil or [] if objects is blank.  # Eager load performs a left outer join between the 'objects' and '@table' tables, so that  # entries where a relation is not established are included.  # If no sorting is given, defaults to sort by name (if the object has a name), or by the  # last and first names (for employees)
params
objects