class ActiveModel::Validations::CountriesAlpha3Validator

Public Instance Methods

validate_each(record, attribute, value) click to toggle source
# 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