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 @@