Created
November 28, 2013 15:27
Country seed data using data from the 'countries' gem. Table columns:
- name
- continent
- alpha2_code
- currency_code
- calling_code Adapt for your own use!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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