Skip to content

Commit 9764ab7

Browse files
author
Raushan Kumar Raman
committed
feature(user): improved email already taken message for more clarity message
1 parent d5421a5 commit 9764ab7

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

app/validators/user_validator.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def validate(record)
88
valid_phone_number_if_receive_sms_notifications(record)
99
validate_date_of_birth_in_past(record.date_of_birth, record)
1010
validate_date_of_birth_not_before_1920(record.date_of_birth, record)
11+
validate_email_unique(record)
1112
end
1213

1314
private
@@ -50,4 +51,10 @@ def validate_date_of_birth_not_before_1920(date_of_birth, record)
5051

5152
record.errors.add(:base, " Date of birth must be on or after 1/1/1920.") unless date_of_birth >= "1920-01-01".to_date
5253
end
54+
55+
def validate_email_unique(record)
56+
if User.exists?(email: record.email)
57+
record.errors.add(:base, I18n.t('activerecord.errors.messages.email_uniqueness'))
58+
end
59+
end
5360
end

0 commit comments

Comments
 (0)