Browse Source

Clean user error messages

pull/2596/head
Kat 2 years ago
parent
commit
7d817c1b3d
  1. 15
      app/helpers/user_helper.rb
  2. 1
      app/views/users/edit.html.erb

15
app/helpers/user_helper.rb

@ -41,4 +41,19 @@ module UserHelper
"You’re moving #{user.name} from #{user.organisation.name} to #{new_organisation.name}. #{log_reassignment_text}" "You’re moving #{user.name} from #{user.organisation.name} to #{new_organisation.name}. #{log_reassignment_text}"
end end
def remove_attributes_from_error_messages(user)
modified_errors = []
user.errors.each do |error|
cleaned_message = error.type.gsub(error.attribute.to_s.humanize, "").strip
modified_errors << [error.attribute, cleaned_message]
end
user.errors.clear
modified_errors.each do |attribute, message|
user.errors.add(attribute, message)
end
end
end end

1
app/views/users/edit.html.erb

@ -7,6 +7,7 @@
<%= form_for(@user, as: :user, html: { method: :patch }) do |f| %> <%= form_for(@user, as: :user, html: { method: :patch }) do |f| %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<% remove_attributes_from_error_messages(@user) %>
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>
<h1 class="govuk-heading-l"> <h1 class="govuk-heading-l">

Loading…
Cancel
Save