Fix bug.
This commit is contained in:
parent
cb46139ca8
commit
42569fd0b7
|
@ -10,9 +10,13 @@ class SurveyAnswer
|
||||||
belongs_to :questionnaire_survey
|
belongs_to :questionnaire_survey
|
||||||
after_create do
|
after_create do
|
||||||
if self.questionnaire_survey
|
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?
|
if answer_group.nil?
|
||||||
answer_group = SurveyAnswerGroup.new(:questionnaire_survey_id=>self.questionnaire_survey.id,:user=>user_id)
|
answer_group = SurveyAnswerGroup.new(info)
|
||||||
end
|
end
|
||||||
answer_group.last_modified = self.updated_at
|
answer_group.last_modified = self.updated_at
|
||||||
answer_group.survey_answer_ids << self.id
|
answer_group.survey_answer_ids << self.id
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
<h3><%= @survey.title %></h3>
|
<h3><%= @survey.title %></h3>
|
||||||
<div>
|
<div>
|
||||||
<% if @is_answer_list %>
|
<% if @is_answer_list %>
|
||||||
<h4><%=t('survey.taken_by')%>: <%=@user.member_name%></h4>
|
<h4><%=t('survey.taken_by')%>: <%=@user.member_name rescue "NA" %></h4>
|
||||||
<% else %>
|
<% else %>
|
||||||
<form id="survey_answer_search">
|
<form id="survey_answer_search">
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -6,14 +6,30 @@ Rails.application.routes.draw do
|
||||||
surveys.each do |survey|
|
surveys.each do |survey|
|
||||||
group_data = survey.survey_answers.asc(:updated_at).group_by(&:user)
|
group_data = survey.survey_answers.asc(:updated_at).group_by(&:user)
|
||||||
group_data.each do |user_id,survey_answers|
|
group_data.each do |user_id,survey_answers|
|
||||||
answer_group = SurveyAnswerGroup.where(:questionnaire_survey_id=>survey.id,:user=>user_id).first
|
org_updated_at = survey_answers.map{|a| a.updated_at}
|
||||||
|
if user_id.blank?
|
||||||
|
survey_answers.each do |survey_answer|
|
||||||
|
info = {:questionnaire_survey_id=>survey.id,:user=>user_id,:survey_answer_ids=>[survey_answer.id]}
|
||||||
|
answer_group = SurveyAnswerGroup.where(info).first
|
||||||
if answer_group.nil?
|
if answer_group.nil?
|
||||||
answer_group = SurveyAnswerGroup.new(:questionnaire_survey_id=>survey.id,:user=>user_id)
|
info.delete(:survey_answer_ids)
|
||||||
|
answer_group = SurveyAnswerGroup.new(info)
|
||||||
|
end
|
||||||
|
answer_group.last_modified = survey_answer.updated_at
|
||||||
|
answer_group.survey_answer_ids = [survey_answer.id]
|
||||||
|
answer_group.save
|
||||||
|
end
|
||||||
|
else
|
||||||
|
info = {:questionnaire_survey_id=>survey.id,:user=>user_id}
|
||||||
|
answer_group = SurveyAnswerGroup.where(info).first
|
||||||
|
if answer_group.nil?
|
||||||
|
answer_group = SurveyAnswerGroup.new(info)
|
||||||
end
|
end
|
||||||
answer_group.last_modified = survey_answers.last.updated_at
|
answer_group.last_modified = survey_answers.last.updated_at
|
||||||
answer_group.survey_answer_ids = survey_answers.map{|a| a.id}
|
answer_group.survey_answer_ids = survey_answers.map{|a| a.id}
|
||||||
answer_group.save
|
answer_group.save
|
||||||
survey_answers.each{|a| a.updated_at = a.created_at;a.save}
|
end
|
||||||
|
survey_answers.each_with_index{|a,i| a.updated_at = org_updated_at[i];a.save}
|
||||||
end
|
end
|
||||||
survey.already_fix_data = true
|
survey.already_fix_data = true
|
||||||
survey.survey_questions.each do |q|
|
survey.survey_questions.each do |q|
|
||||||
|
|
Loading…
Reference in New Issue