|
|
|
@ -14,19 +14,15 @@ class ExerciseAnswersController < ApplicationController
|
|
|
|
|
else
|
|
|
|
|
ea = @exercise_question.exercise_answers.search_answer_users("user_id",current_user.id) #试卷的当前用户的答案
|
|
|
|
|
if q_type == Exercise::SINGLE || q_type == Exercise::JUDGMENT #选择题(单选)/判断题
|
|
|
|
|
ea_choice = ea.search_exercise_answer("exercise_choice_id",choice_id).first
|
|
|
|
|
answer_option = {
|
|
|
|
|
if ea.exists?
|
|
|
|
|
ea.first.update_attribute(:exercise_choice_id,choice_id )
|
|
|
|
|
else
|
|
|
|
|
answer_option = {
|
|
|
|
|
:user_id => current_user.id,
|
|
|
|
|
:exercise_question_id => @exercise_question.id,
|
|
|
|
|
:exercise_choice_id => choice_id,
|
|
|
|
|
:answer_text => ""
|
|
|
|
|
}
|
|
|
|
|
if ea_choice.present? #如果当前用户的答案存在,再次点击,即为删除
|
|
|
|
|
ea_choice.destroy
|
|
|
|
|
else
|
|
|
|
|
if @exercise_question.exercise_standard_answers.count <= 1 #单选题的时候
|
|
|
|
|
ea.first.destroy if ea.present?
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
ex_a = ExerciseAnswer.new(answer_option)
|
|
|
|
|
ex_a.save!
|
|
|
|
|
end
|
|
|
|
|