diff --git a/app/controllers/concerns/paginator.rb b/app/controllers/concerns/paginator.rb index fa68416d0d8a1dd4133f497a78d9ac84162b2e7c..8a602781a65f711ff5609774f552d21bf830d055 100644 --- a/app/controllers/concerns/paginator.rb +++ b/app/controllers/concerns/paginator.rb @@ -54,7 +54,7 @@ module Paginator # ordering to_sort = JSON.parse params[:sort] if !params[:sort].blank? - model = model.order("#{to_sort[0]} #{to_sort[1]}") if !to_sort.blank? + model = model.order("\"#{model.table_name}\".\"#{to_sort[0]}\" #{to_sort[1]}") if !to_sort.blank? return model end diff --git a/app/controllers/v1/learning_objects_controller.rb b/app/controllers/v1/learning_objects_controller.rb index 1a9913e88f2727c3e3e25fab942b5b8d935c4fdd..b8e8acfb1c2ebb101b19b30ef4527698ec2fb2e0 100644 --- a/app/controllers/v1/learning_objects_controller.rb +++ b/app/controllers/v1/learning_objects_controller.rb @@ -39,7 +39,10 @@ class V1::LearningObjectsController < ApplicationController before_action :set_paper_trail_whodunnit, except: [:index, :show] def index - learning_objects = paginate policy_scope(LearningObject).includes(:tags, :publisher, :language, :license, :subjects, :educational_stages, :reviews).order(score: :desc) + + learning_objects = policy_scope(LearningObject).includes(:tags, :publisher, :language, :license, :subjects, :educational_stages, :reviews) + learning_objects = learning_objects.order(score: :desc) if params[:sort].blank? + learning_objects = paginate learning_objects serializer = params[:obaa].nil? ? LearningObjectSerializer : LearningObjectObaaSerializer http_cache_forever do render json: learning_objects, each_serializer: serializer