From 9384f76b4521403e46fa948d9fe29cd092f5e342 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 12 Sep 2019 16:29:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E8=AF=84=E8=AF=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_questions_controller.rb | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 20feaecfe..7e0b612ff 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -526,8 +526,7 @@ class ExerciseQuestionsController < ApplicationController :score => @c_score, :answer_text => "" } - ex_answer_create = ExerciseAnswer.new(answer_option) - ex_answer_create.save + ExerciseAnswer.new(answer_option) ex_answer_old = 0 end if ex_obj_score <= 0.0 @@ -628,23 +627,18 @@ class ExerciseQuestionsController < ApplicationController end comments = params[:comment] question_comment = @exercise_question.exercise_answer_comments&.first + if question_comment.present? comment_option = { :comment => comments.present? ? comments : question_comment.comment, :score => @c_score, - :exercise_answer_id => ex_answers.present? ? ex_answers.first.id : nil + :exercise_answer_id => ex_answers.present? ? ex_answers.first.id : nil, + :user_id => current_user.id } question_comment.update_attributes(comment_option) @exercise_comments = question_comment else - if ex_answers.present? - ex_answer_comment_id = ex_answers.first.id - elsif ex_answer_create.present? - ex_answer_comment_id = ex_answer_create.id - else - ex_answer_comment_id = nil - end - + ex_answer_comment_id = @exercise_question.exercise_answers.find_by(user_id: @user_id).try(:id) comment_option = { :user_id => current_user.id, :comment => comments,