Are you just trying to confirm that the entered country code is suitable? this should work withcarmen
validates :country, inclusion:{in:Carmen::Country.all.map(&:code)}
, , , . countries
validates :country, inclusion:{in:Country.all.map(&:pop)}
validate :country_is_iso_compliant
def country_is_iso_compliant
errors.add(:country, "must be 2 characters (ISO 3166-1).") unless Country[country]
end
3 .
validates :country, :region, :state, presence: true
validate :location
def location
current_country = Country[country]
if current_country
errors.add(:region, "incorrect region for country #{current_country.name}.") unless current_country.region == region
errors.add(:state, "incorrect state for country #{current_country.name}.") unless current_country.states.keys.include?(state)
else
errors.add(:country, "must be a 2 character country representation (ISO 3166-1).")
end
end
, ,
before_validation {|record| record.region = Country[country].region if Country[country]}