From 0e9168634fd303863df616c4eb6eb042fc201601 Mon Sep 17 00:00:00 2001 From: BoHung Chiu Date: Thu, 26 Jan 2023 11:45:42 +0800 Subject: [PATCH] Fix bug. --- app/controllers/asks_controller.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/controllers/asks_controller.rb b/app/controllers/asks_controller.rb index f44ee5f..6a59827 100644 --- a/app/controllers/asks_controller.rb +++ b/app/controllers/asks_controller.rb @@ -19,10 +19,12 @@ class AsksController < ApplicationController else categories = Category.where(:id.in=>OrbitHelper.widget_categories).enabled end - if (module_app.asc rescue true) - categories = categories.sort_by{|category| (category.sort_number.to_i rescue category.id)} - else - categories = categories.sort_by{|category| (-category.sort_number.to_i rescue category.id)} + unless Category.respond_to?(:sorted) + if (module_app.asc rescue true) + categories = categories.sort_by{|category| (category.sort_number.to_i rescue category.id)} + else + categories = categories.sort_by{|category| (-category.sort_number.to_i rescue category.id)} + end end tags = module_app.tags ask_question = AskQuestion.new @@ -132,10 +134,12 @@ class AsksController < ApplicationController else categories = Category.where(:id.in=>OrbitHelper.page_categories).enabled end - if (module_app.asc rescue true) - categories = categories.sort_by{|category| (category.sort_number.to_i rescue category.id)} - else - categories = categories.sort_by{|category| (-category.sort_number.to_i rescue category.id)} + unless Category.respond_to?(:sorted) + if (module_app.asc rescue true) + categories = categories.sort_by{|category| (category.sort_number.to_i rescue category.id)} + else + categories = categories.sort_by{|category| (-category.sort_number.to_i rescue category.id)} + end end category_ids = categories.collect{|v| v.id.to_s} ask_settings = AskCategorySetting.enabled.where(:category_id.in=> category_ids).to_a