summaryrefslogtreecommitdiff
path: root/app/helpers/form_helper.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/helpers/form_helper.rb')
-rw-r--r--app/helpers/form_helper.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/app/helpers/form_helper.rb b/app/helpers/form_helper.rb
new file mode 100644
index 00000000000..6a43be2cf3e
--- /dev/null
+++ b/app/helpers/form_helper.rb
@@ -0,0 +1,18 @@
+module FormHelper
+ def form_errors(model)
+ return unless model.errors.any?
+
+ pluralized = 'error'.pluralize(model.errors.count)
+ headline = "The form contains the following #{pluralized}:"
+
+ content_tag(:div, class: 'alert alert-danger', id: 'error_explanation') do
+ content_tag(:h4, headline) <<
+ content_tag(:ul) do
+ model.errors.full_messages.
+ map { |msg| content_tag(:li, msg) }.
+ join.
+ html_safe
+ end
+ end
+ end
+end