From aa4dfd6190599fdfdbd21d50b37e1e3a6839eb97 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 14:10:09 +0800 Subject: [PATCH] fix bug --- app/helpers/exercises_helper.rb | 10 +++++----- app/views/exercises/start_answer.json.jbuilder | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 8db7e8bfa..cec6dd0ff 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -46,7 +46,7 @@ module ExercisesHelper sub_answer_score = sub_answer.first.score else stand_status = 0 - sub_answer_score = 0.0 + sub_answer_score = nil end sub_score = { @@ -54,7 +54,7 @@ module ExercisesHelper "q_type":s.question_type, "q_position":s.question_number, "stand_status":stand_status, - "user_score":sub_answer_score.round(1).to_s + "user_score":sub_answer_score.present? ? sub_answer_score.round(1).to_s : nil } @ex_sub_array.push(sub_score) end @@ -627,7 +627,7 @@ module ExercisesHelper #学生的分数状态及回答的内容 def user_question_answers(q,ex_answerer_id,student_status,is_teacher_or,ex_status,ques_type,ex_type) answered_content = [] - user_score = 0.0 + user_score = nil shixun_type = 0 question_comment = [] if q.question_type == 5 @@ -638,7 +638,7 @@ module ExercisesHelper if student_status == 2 #当前为老师,或为学生且已提交 user_score = exercise_answers.score_reviewed.pluck(:score).sum end - if user_score > q.question_score + if user_score.present? && (user_score > q.question_score) user_score = q.question_score end if ques_type <= 2 @@ -667,7 +667,7 @@ module ExercisesHelper question_comment = q.exercise_answer_comments.search_answer_comments("exercise_answer_id",q_answer_id) end { - "user_score": user_score.round(1), + "user_score": user_score.present? ? user_score.round(1) : nil, "answered_content":answered_content, "shixun_type":shixun_type, "question_comment":question_comment diff --git a/app/views/exercises/start_answer.json.jbuilder b/app/views/exercises/start_answer.json.jbuilder index 4cc461d56..42d611712 100644 --- a/app/views/exercises/start_answer.json.jbuilder +++ b/app/views/exercises/start_answer.json.jbuilder @@ -40,8 +40,8 @@ json.exercise_questions do question_info = get_exercise_question_info(question,@exercise,@exercise_user_current,@ex_answerer.id) # json.q_position q[:ques_number] #问题的序号,当问题为随机时,重新更新后的问题序号 if @t_user_exercise_status == 3 - this_answer_status = "0.0" - user_score = "0.0" + this_answer_status = 0 + user_score = nil if all_question_status.size > 0 this_ques_status = all_question_status.detect {|f| f[:q_id] == question.id} this_answer_status = this_ques_status[:stand_status]