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 @@ ...@@ -2,19 +2,29 @@
module FormHelper module FormHelper
def form_errors(model, type: 'form', truncate: []) 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) truncate = Array.wrap(truncate)
content_tag(:div, class: 'alert alert-danger', id: 'error_explanation') do tag.div(class: 'alert alert-danger', id: 'error_explanation') do
content_tag(:h4, headline) << tag.h4(headline) <<
content_tag(:ul) do tag.ul do
messages = model.errors.map do |attribute, message| messages = errors.map do |error|
message = html_escape_once(model.errors.full_message(attribute, message)).html_safe attribute = error.attribute
message = content_tag(:span, message, class: 'str-truncated-100') if truncate.include?(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 end
messages.join.html_safe 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