Class: ActiveModel::Validations::CountriesAlpha2Validator
- Inherits:
-
EachValidator
- Object
- EachValidator
- ActiveModel::Validations::CountriesAlpha2Validator
- Defined in:
- lib/rails-countries/validators.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
7 8 9 |
# File 'lib/rails-countries/validators.rb', line 7 def validate_each(record, attribute, value) record.errors.add(attribute, :countries_alpha2_invalid, alpha2: value) if value.present? && (value.is_a?(String) || value.is_a?(Symbol)) && !ISO3166::Country.all.map(&:alpha2).include?(value.to_s) end |