From bb726e3475682c509c498ca9bf7179b8b71494a5 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 20 Nov 2015 18:21:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E7=AD=94=E6=A1=88=E9=AA=8C?= =?UTF-8?q?=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 18 ++++-------------- app/helpers/exercise_helper.rb | 11 +++++++++++ .../exercise/_exercise_student_result.html.erb | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index cbc6009b1..781ea50cd 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -485,7 +485,10 @@ class ExerciseController < ApplicationController score2 = score + question.question_score unless question.question_score.nil? end else - get_mulscore(question, user, standard_answer) + arr = get_mulscore(question, user) + if arr.to_i == standard_answer.exercise_choice_id + score3 = score + question.question_score unless question.question_score.nil? + end # ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) # arr = [] # ecs.each do |ec| @@ -503,19 +506,6 @@ class ExerciseController < ApplicationController end private - # 获取多选的得分 - def get_mulscore(question, user, standard_answer) - ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) - arr = [] - ecs.each do |ec| - arr << ec.exercise_choice.choice_position - end - arr.sort - arr = arr.join("") - if arr.to_i == standard_answer.exercise_choice_id - score3 = score + question.question_score unless question.question_score.nil? - end - end # ExerciseUser记录用户是否已提交问卷有对应的记录则已提交,没有则新建一个 def get_exercise_user exercise_id,user_id diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb index 21c0144b9..bb87f3b82 100644 --- a/app/helpers/exercise_helper.rb +++ b/app/helpers/exercise_helper.rb @@ -36,6 +36,17 @@ module ExerciseHelper end end + # 获取多选的得分 + def get_mulscore(question, user) + ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) + arr = [] + ecs.each do |ec| + arr << ec.exercise_choice.choice_position + end + arr.sort + arr = arr.join("") + end + # 判断用户是否已经提交了问卷 # status 为0的时候是用户点击试卷。为1表示用户已经提交 def has_commit_exercise?(exercise_id, user_id) diff --git a/app/views/exercise/_exercise_student_result.html.erb b/app/views/exercise/_exercise_student_result.html.erb index 95ef022d5..32cb556b3 100644 --- a/app/views/exercise/_exercise_student_result.html.erb +++ b/app/views/exercise/_exercise_student_result.html.erb @@ -70,7 +70,7 @@ <% answer = get_user_answer(exercise_question, User.current)%> <% standard_answer = get_user_standard_answer(exercise_question, User.current)%> - <% if answer.first.exercise_choice_id == standard_answer.first.exercise_choice_id %> + <% if get_mulscore(exercise_question, User.current).to_i == standard_answer.first.exercise_choice_id %> √ <% else %> ×