diff --git a/plugins/custom_forms/lib/custom_forms_plugin/membership_survey.rb b/plugins/custom_forms/lib/custom_forms_plugin/membership_survey.rb index f200c64..fa13893 100644 --- a/plugins/custom_forms/lib/custom_forms_plugin/membership_survey.rb +++ b/plugins/custom_forms/lib/custom_forms_plugin/membership_survey.rb @@ -13,7 +13,21 @@ class CustomFormsPlugin::MembershipSurvey < Task answers = build_answers(submission, form) s = CustomFormsPlugin::Submission.create!(:form => form, :profile => target) - answers.map {|answer| answer.submission = s; answer.save!} + s.answers.push(*answers) + + failed_answers = answers.select {|answer| !answer.valid? } + if failed_answers.empty? + s.save! + else + s.errors.clear + answers.each do |answer| + answer.valid? + answer.errors.each do |attribute, msg| + s.errors.add(answer.field.id.to_s.to_sym, msg) + end + end + raise ActiveRecord::RecordInvalid, s + end end def title -- libgit2 0.21.2