From 3cb47369e3969ca6e5d88fa14c34af81c99b3f05 Mon Sep 17 00:00:00 2001 From: Larissa Reis Date: Sat, 28 Dec 2013 11:42:50 -0300 Subject: [PATCH] Improves error message for forms in task page --- plugins/custom_forms/lib/custom_forms_plugin/membership_survey.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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