app/controllers/simple_admin/resources_controller.rb in simpleadmin-1.0.2 vs app/controllers/simple_admin/resources_controller.rb in simpleadmin-1.0.3
- old
+ new
@@ -6,20 +6,25 @@
per_page = params[:per_page].to_i
page = params[:page].to_i if params[:page].present?
total = model_klass.count
- resources = model_klass.order(id: :asc).limit(per_page)
+ resources = model_klass.limit(per_page)
if params[:query].present?
search_result = search(params[:query], model_klass, params[:model_attributes])
resources = search_result[:resources]
total = search_result[:total]
end
resources = resources.offset((per_page * page) - per_page) if page.present?
- resources = resources.order(params[:sort][:column_name] => params[:sort][:order]) if params[:sort].present?
+
+ if params[:sort].present?
+ resources = resources.order(params[:sort][:column_name] => params[:sort][:order])
+ else
+ resources = resources.order(id: :asc)
+ end
resources = resources.map do |resource|
_resource = {}
resource.attributes.each do |attribute_name, attribute_value|