Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/helpers/form_helper.rb')
-rw-r--r--app/helpers/form_helper.rb28
1 files changed, 19 insertions, 9 deletions
diff --git a/app/helpers/form_helper.rb b/app/helpers/form_helper.rb
index cf3e99eee49..9b4d0c0b9b3 100644
--- a/app/helpers/form_helper.rb
+++ b/app/helpers/form_helper.rb
@@ -2,19 +2,29 @@
module FormHelper
def form_errors(model, type: 'form', truncate: [])
- return unless model.errors.any?
+ errors = model.errors
+
+ return unless errors.any?
+
+ headline = n_(
+ 'The %{type} contains the following error:',
+ 'The %{type} contains the following errors:',
+ errors.count
+ ) % { type: type }
- headline = n_('The %{type} contains the following error:', 'The %{type} contains the following errors:', model.errors.count) % { type: type }
truncate = Array.wrap(truncate)
- content_tag(:div, class: 'alert alert-danger', id: 'error_explanation') do
- content_tag(:h4, headline) <<
- content_tag(:ul) do
- messages = model.errors.map do |attribute, message|
- message = html_escape_once(model.errors.full_message(attribute, message)).html_safe
- message = content_tag(:span, message, class: 'str-truncated-100') if truncate.include?(attribute)
+ tag.div(class: 'alert alert-danger', id: 'error_explanation') do
+ tag.h4(headline) <<
+ tag.ul do
+ messages = errors.map do |error|
+ attribute = error.attribute
+ message = error.message
+
+ message = html_escape_once(errors.full_message(attribute, message)).html_safe
+ message = tag.span(message, class: 'str-truncated-100') if truncate.include?(attribute)
- content_tag(:li, message)
+ tag.li(message)
end
messages.join.html_safe