Class: ActiveModel::Validations::CountriesAlpha3Validator

Inherits:
EachValidator
  • Object
show all
Defined in:
lib/rails-countries/validators.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



13
14
15
# File 'lib/rails-countries/validators.rb', line 13

def validate_each(record, attribute, value)
  record.errors.add(attribute, :countries_alpha3_invalid, alpha3: value) if value.present? && (value.is_a?(String) || value.is_a?(Symbol)) && !ISO3166::Country.all.map(&:alpha3).include?(value.to_s)
end