From e7b0d82a608ca3df7cc1ac399f9cf660abfe9fe1 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 16 Oct 2019 14:23:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E5=88=97=E8=A1=A8=E6=8E=92=E5=BA=8F=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admins/shixun_settings_controller.rb | 2 +- app/controllers/exercises_controller.rb | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/controllers/admins/shixun_settings_controller.rb b/app/controllers/admins/shixun_settings_controller.rb index 9202ccce6..9919c7daa 100644 --- a/app/controllers/admins/shixun_settings_controller.rb +++ b/app/controllers/admins/shixun_settings_controller.rb @@ -46,7 +46,7 @@ class Admins::ShixunSettingsController < Admins::BaseController tag_ids.each do |id| unless tag_repertoire_ids.include?(id) tag_repertoire = @shixun.shixun_tag_repertoires.new(shixun_id:@shixun.id,tag_repertoire_id:id) - tag_repertoire.save + tag_repertoire.save! end end else diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 74059b314..317760796 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1425,18 +1425,24 @@ class ExercisesController < ApplicationController @exercise_questions = @exercise.exercise_questions&.includes(:exercise_choices,:exercise_answers,:exercise_standard_answers,:exercise_shixun_challenges,:exercise_shixun_answers) - @paging_type = "percent" - # 按题型排序 + percent_sort = "desc" + if params[:sort].present? - @paging_type = params[:sort].to_s + percent_sort = params[:sort] end + # @paging_type = "percent" + # # 按题型排序 + # if params[:sort].present? + # @paging_type = params[:sort].to_s + # end ques_result_all = exercise_commit_result(@exercise_questions,@exercise_commit_user_ids) - if @paging_type == "percent" - @question_result_hash = ques_result_all.sort_by{|s| s[:percent]} + #默认降序排列 + if percent_sort == "desc" + @question_result_hash = ques_result_all.sort_by{|s| s[:percent]}.reverse else - @question_result_hash = ques_result_all.sort_by{|s| s[:"#{@paging_type}"]} + @question_result_hash = ques_result_all.sort_by{|s| s[:percent]} end @exercise_questions_count = @exercise_questions.size