提交答案验证

This commit is contained in:
huang 2015-11-20 18:21:31 +08:00
parent d1e0e0fd30
commit bb726e3475
3 changed files with 16 additions and 15 deletions

View File

@ -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

View File

@ -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)

View File

@ -70,7 +70,7 @@
<span class="ml15 c_red">
<% 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 %>
×