Skip to content

Commit aba460d

Browse files
committed
Return error message if ID exists
1 parent e953dd7 commit aba460d

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

app/models/school.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ class School < ApplicationRecord
1717
validates :municipality, presence: true
1818
validates :country_code, presence: true, inclusion: { in: ISO3166::Country.codes }
1919
validates :reference,
20-
uniqueness: { conditions: -> { where(rejected_at: nil) }, case_sensitive: false, allow_blank: true },
20+
uniqueness: { conditions: -> { where(rejected_at: nil) }, case_sensitive: false, allow_blank: true, message: I18n.t('validations.school.reference_urn_exists') },
2121
format: { with: /\A\d{5,6}\z/, allow_nil: true, message: I18n.t('validations.school.reference') },
2222
if: :united_kingdom?
2323
validates :district_nces_id,
24-
uniqueness: { conditions: -> { where(rejected_at: nil) }, case_sensitive: false, allow_blank: true },
24+
uniqueness: { conditions: -> { where(rejected_at: nil) }, case_sensitive: false, allow_blank: true, message: I18n.t('validations.school.district_nces_id_exists') },
2525
format: { with: /\A\d{12}\z/, allow_nil: true, message: I18n.t('validations.school.district_nces_id') },
2626
presence: true,
2727
if: :united_states?
2828
validates :district_name, presence: true, if: :united_states?
2929
validates :school_roll_number,
30-
uniqueness: { conditions: -> { where(rejected_at: nil) }, case_sensitive: false, allow_blank: true },
30+
uniqueness: { conditions: -> { where(rejected_at: nil) }, case_sensitive: false, allow_blank: true, message: I18n.t('validations.school.school_roll_number_exists') },
3131
format: { with: /\A[0-9]+[A-Z]+\z/, allow_nil: true, message: I18n.t('validations.school.school_roll_number') },
3232
presence: true,
3333
if: :ireland?

config/locales/en.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ en:
1616
school:
1717
website: "must be a valid URL"
1818
reference: "must be 5-6 digits (e.g., 100000)"
19+
reference_urn_exists: "URN number already exists"
1920
district_nces_id: "must be 12 digits (e.g., 010000000001)"
21+
district_nces_id_exists: "NCES ID already exists"
2022
school_roll_number: "must be numbers followed by letters (e.g., 01572D)"
23+
school_roll_number_exists: "School roll number already exists"
2124
invitation:
2225
email_address: "'%<value>s' is invalid"
2326
activerecord:

0 commit comments

Comments
 (0)