From 42569fd0b7676429518fc89a6b08a06df639604c Mon Sep 17 00:00:00 2001 From: Bohung Date: Sun, 12 Sep 2021 20:56:09 +0800 Subject: [PATCH] Fix bug. --- app/models/survey_answer.rb | 8 ++++-- app/views/admin/surveys/answer_sets.html.erb | 2 +- config/routes.rb | 30 +++++++++++++++----- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/app/models/survey_answer.rb b/app/models/survey_answer.rb index 58d792e..1e55407 100644 --- a/app/models/survey_answer.rb +++ b/app/models/survey_answer.rb @@ -10,9 +10,13 @@ class SurveyAnswer belongs_to :questionnaire_survey after_create do if self.questionnaire_survey - answer_group = SurveyAnswerGroup.where(:questionnaire_survey_id=>self.questionnaire_survey.id,:user=>user).first + info = {:questionnaire_survey_id=>self.questionnaire_survey.id,:user=>self.user} + if self.user.blank? + info[:survey_answer_ids] = [self.id] + end + answer_group = SurveyAnswerGroup.where(info).first if answer_group.nil? - answer_group = SurveyAnswerGroup.new(:questionnaire_survey_id=>self.questionnaire_survey.id,:user=>user_id) + answer_group = SurveyAnswerGroup.new(info) end answer_group.last_modified = self.updated_at answer_group.survey_answer_ids << self.id diff --git a/app/views/admin/surveys/answer_sets.html.erb b/app/views/admin/surveys/answer_sets.html.erb index 6e9508d..4d9a00f 100644 --- a/app/views/admin/surveys/answer_sets.html.erb +++ b/app/views/admin/surveys/answer_sets.html.erb @@ -33,7 +33,7 @@

<%= @survey.title %>

<% if @is_answer_list %> -

<%=t('survey.taken_by')%>: <%=@user.member_name%>

+

<%=t('survey.taken_by')%>: <%=@user.member_name rescue "NA" %>

<% else %>