Skip to content

Instantly share code, notes, and snippets.

@yctay
Created November 28, 2013 15:27
Show Gist options
  • Save yctay/7693706 to your computer and use it in GitHub Desktop.
Save yctay/7693706 to your computer and use it in GitHub Desktop.
Country seed data using data from the 'countries' gem. Table columns: - name - continent - alpha2_code - currency_code - calling_code Adapt for your own use!
# Countries
# `alpha2_code` has unique constraint
countries_seed_file = File.join(Rails.root, 'db', 'seeds', 'countries.yml')
countries = YAML.load_file(countries_seed_file)
countries.each do |country|
country = country[-1]
data = {
name: country['name'],
continent: country['continent'],
alpha2_code: country['alpha2'],
currency_code: country['currency'] || "",
calling_code: country['country_code'].to_i
}
begin
Country.create(data)
rescue
next
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment