From fc30bf8cac4281a468f1b6aae79eb1de5266a19d Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sat, 21 Jan 2023 13:14:15 +0100 Subject: [PATCH] Add more explicit message for format validation errors --- app/models/user.rb | 2 +- config/locales/activerecord.en.yml | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 6e3ed1da..fb32d232 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -63,7 +63,7 @@ class User < ApplicationRecord # rubocop:disable Metrics/ClassLength validates :email, fake_email: true, typoed_email: true validates :screen_name, presence: true, - format: { with: SCREEN_NAME_REGEX }, + format: { with: SCREEN_NAME_REGEX, message: I18n.t("activerecord.validation.user.screen_name.format") }, length: { minimum: 1, maximum: 16 }, uniqueness: { case_sensitive: false }, screen_name: true diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index 91605b34..c14e12b4 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -96,6 +96,10 @@ en: primary_color: "The primary/brand colour of the site, used for navigation, links, etc." success_color: "Colour used for messages if something went through successfully." warning_color: "Colour used for warnings if something non-critical has happened." + validation: + user: + screen_name: + format: "contains invalid characters" helpers: submit: user: