From cbf0d74eea4d319311c3728c00e4f09ab8066d7e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 12 Sep 2019 16:13:27 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=AC=AC=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E8=B0=83=E5=88=86=E8=AF=84=E8=AF=AD=E6=B2=A1=E6=9C=89=E5=87=BA?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_questions_controller.rb | 5 +++-- app/models/exercise_answer_comment.rb | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 5032cb469..affbdcd56 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -525,7 +525,8 @@ class ExerciseQuestionsController < ApplicationController :score => @c_score, :answer_text => "" } - ExerciseAnswer.create(answer_option) + ex_answers = ExerciseAnswer.new(answer_option) + ex_answers.save ex_answer_old = 0 end if ex_obj_score <= 0.0 @@ -625,7 +626,7 @@ class ExerciseQuestionsController < ApplicationController @exercise_current_user.update_attributes(ex_scores) end comments = params[:comment] - question_comment = @exercise_question.exercise_answer_comments.first + question_comment = @exercise_question.exercise_answer_comments&.first if question_comment.present? comment_option = { :comment => comments.present? ? comments : question_comment.comment, diff --git a/app/models/exercise_answer_comment.rb b/app/models/exercise_answer_comment.rb index 7da0ec4c7..4279ba445 100644 --- a/app/models/exercise_answer_comment.rb +++ b/app/models/exercise_answer_comment.rb @@ -3,7 +3,7 @@ class ExerciseAnswerComment < ApplicationRecord belongs_to :user belongs_to :exercise_question belongs_to :exercise_shixun_answer, optional: true - belongs_to :exercise_answer,optional: true + belongs_to :exercise_answer, optional: true scope :search_answer_comments, lambda {|name,ids| where("#{name}":ids)} end