Commit 9b5aab7c authored by Etienne Baqué's avatar Etienne Baqué

Merge branch 'tancnle-fix-rails-errors-deprecation-warning' into 'master'

Fix deprecation warning in ActiveModel::Errors

See merge request gitlab-org/gitlab!63717
parents dccca378 efd546a0
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment