Commit 3cb47369e3969ca6e5d88fa14c34af81c99b3f05
1 parent
bedac4e4
Exists in
master
and in
28 other branches
Improves error message for forms in task page
Showing
1 changed file
with
15 additions
and
1 deletions
Show diff stats
plugins/custom_forms/lib/custom_forms_plugin/membership_survey.rb
... | ... | @@ -13,7 +13,21 @@ class CustomFormsPlugin::MembershipSurvey < Task |
13 | 13 | |
14 | 14 | answers = build_answers(submission, form) |
15 | 15 | s = CustomFormsPlugin::Submission.create!(:form => form, :profile => target) |
16 | - answers.map {|answer| answer.submission = s; answer.save!} | |
16 | + s.answers.push(*answers) | |
17 | + | |
18 | + failed_answers = answers.select {|answer| !answer.valid? } | |
19 | + if failed_answers.empty? | |
20 | + s.save! | |
21 | + else | |
22 | + s.errors.clear | |
23 | + answers.each do |answer| | |
24 | + answer.valid? | |
25 | + answer.errors.each do |attribute, msg| | |
26 | + s.errors.add(answer.field.id.to_s.to_sym, msg) | |
27 | + end | |
28 | + end | |
29 | + raise ActiveRecord::RecordInvalid, s | |
30 | + end | |
17 | 31 | end |
18 | 32 | |
19 | 33 | def title | ... | ... |