Country Seed Data for your Rails App

Never go looking for basic country seed data again:

[
  { :name => 'Afghanistan', :iso_two_letter_code => 'AF' },
  { :name => 'Aland Islands', :iso_two_letter_code => 'AX' },
  { :name => 'Albania', :iso_two_letter_code => 'AL' },
  { :name => 'Algeria', :iso_two_letter_code => 'DZ' },
  { :name => 'American Samoa', :iso_two_letter_code => 'AS' },
  { :name => 'Andorra', :iso_two_letter_code => 'AD' },
  { :name => 'Angola', :iso_two_letter_code => 'AO' },
  { :name => 'Anguilla', :iso_two_letter_code => 'AI' },
  { :name => 'Antarctica', :iso_two_letter_code => 'AQ' },
  { :name => 'Antigua And Barbuda', :iso_two_letter_code => 'AG' },
  { :name => 'Argentina', :iso_two_letter_code => 'AR' },
  { :name => 'Armenia', :iso_two_letter_code => 'AM' },
  { :name => 'Aruba', :iso_two_letter_code => 'AW' },
  { :name => 'Australia', :iso_two_letter_code => 'AU' },
  { :name => 'Austria', :iso_two_letter_code => 'AT' },
  { :name => 'Azerbaijan', :iso_two_letter_code => 'AZ' },
  { :name => 'Bahamas', :iso_two_letter_code => 'BS' },
  { :name => 'Bahrain', :iso_two_letter_code => 'BH' },
  { :name => 'Bangladesh', :iso_two_letter_code => 'BD' },
  { :name => 'Barbados', :iso_two_letter_code => 'BB' },
  { :name => 'Belarus', :iso_two_letter_code => 'BY' },
  { :name => 'Belgium', :iso_two_letter_code => 'BE' },
  { :name => 'Belize', :iso_two_letter_code => 'BZ' },
  { :name => 'Benin', :iso_two_letter_code => 'BJ' },
  { :name => 'Bermuda', :iso_two_letter_code => 'BM' },
  { :name => 'Bhutan', :iso_two_letter_code => 'BT' },
  { :name => 'Bolivia', :iso_two_letter_code => 'BO' },
  { :name => 'Bosnia and Herzegovina', :iso_two_letter_code => 'BA' },
  { :name => 'Botswana', :iso_two_letter_code => 'BW' },
  { :name => 'Bouvet Island', :iso_two_letter_code => 'BV' },
  { :name => 'Brazil', :iso_two_letter_code => 'BR' },
  { :name => 'British Indian Ocean Territory', :iso_two_letter_code => 'IO' },
  { :name => 'Brunei Darussalam', :iso_two_letter_code => 'BN' },
  { :name => 'Bulgaria', :iso_two_letter_code => 'BG' },
  { :name => 'Burkina Faso', :iso_two_letter_code => 'BF' },
  { :name => 'Burundi', :iso_two_letter_code => 'BI' },
  { :name => 'Cambodia', :iso_two_letter_code => 'KH' },
  { :name => 'Cameroon', :iso_two_letter_code => 'CM' },
  { :name => 'Canada', :iso_two_letter_code => 'CA' },
  { :name => 'Cape Verde', :iso_two_letter_code => 'CV' },
  { :name => 'Cayman Islands', :iso_two_letter_code => 'KY' },
  { :name => 'Central African Republic', :iso_two_letter_code => 'CF' },
  { :name => 'Chad', :iso_two_letter_code => 'TD' },
  { :name => 'Chile', :iso_two_letter_code => 'CL' },
  { :name => 'China', :iso_two_letter_code => 'CN' },
  { :name => 'Christmas Island', :iso_two_letter_code => 'CX' },
  { :name => 'Cocos (Keeling) Islands', :iso_two_letter_code => 'CC' },
  { :name => 'Colombia', :iso_two_letter_code => 'CO' },
  { :name => 'Comoros', :iso_two_letter_code => 'KM' },
  { :name => 'Congo', :iso_two_letter_code => 'CG' },
  { :name => 'Congo (DRC)', :iso_two_letter_code => 'CD' },
  { :name => 'Cook Islands', :iso_two_letter_code => 'CK' },
  { :name => 'Costa Rica', :iso_two_letter_code => 'CR' },
  { :name => 'Cote d\'Ivoire', :iso_two_letter_code => 'CI' },
  { :name => 'Croatia', :iso_two_letter_code => 'HR' },
  { :name => 'Cuba', :iso_two_letter_code => 'CU' },
  { :name => 'Cyprus', :iso_two_letter_code => 'CY' },
  { :name => 'Czech Republic', :iso_two_letter_code => 'CZ' },
  { :name => 'Denmark', :iso_two_letter_code => 'DK' },
  { :name => 'Djibouti', :iso_two_letter_code => 'DJ' },
  { :name => 'Dominica', :iso_two_letter_code => 'DM' },
  { :name => 'Dominican Republic', :iso_two_letter_code => 'DO' },
  { :name => 'Ecuador', :iso_two_letter_code => 'EC' },
  { :name => 'Egypt', :iso_two_letter_code => 'EG' },
  { :name => 'El Salvador', :iso_two_letter_code => 'SV' },
  { :name => 'Equatorial Guinea', :iso_two_letter_code => 'GQ' },
  { :name => 'Eritrea', :iso_two_letter_code => 'ER' },
  { :name => 'Estonia', :iso_two_letter_code => 'EE' },
  { :name => 'Ethiopia', :iso_two_letter_code => 'ET' },
  { :name => 'Falkland Islands', :iso_two_letter_code => 'FK' },
  { :name => 'Faroe Islands', :iso_two_letter_code => 'FO' },
  { :name => 'Fiji', :iso_two_letter_code => 'FJ' },
  { :name => 'Finland', :iso_two_letter_code => 'FI' },
  { :name => 'France', :iso_two_letter_code => 'FR' },
  { :name => 'French Guiana', :iso_two_letter_code => 'GF' },
  { :name => 'French Polynesia', :iso_two_letter_code => 'PF' },
  { :name => 'French Southern Territories', :iso_two_letter_code => 'TF' },
  { :name => 'Gabon', :iso_two_letter_code => 'GA' },
  { :name => 'Gambia', :iso_two_letter_code => 'GM' },
  { :name => 'Georgia', :iso_two_letter_code => 'GE' },
  { :name => 'Germany', :iso_two_letter_code => 'DE' },
  { :name => 'Ghana', :iso_two_letter_code => 'GH' },
  { :name => 'Gibraltar', :iso_two_letter_code => 'GI' },
  { :name => 'Greece', :iso_two_letter_code => 'GR' },
  { :name => 'Greenland', :iso_two_letter_code => 'GL' },
  { :name => 'Grenada', :iso_two_letter_code => 'GD' },
  { :name => 'Guadeloupe', :iso_two_letter_code => 'GP' },
  { :name => 'Guam', :iso_two_letter_code => 'GU' },
  { :name => 'Guatemala', :iso_two_letter_code => 'GT' },
  { :name => 'Guernsey', :iso_two_letter_code => 'GG' },
  { :name => 'Guinea', :iso_two_letter_code => 'GN' },
  { :name => 'Guinea-Bissau', :iso_two_letter_code => 'GW' },
  { :name => 'Guyana', :iso_two_letter_code => 'GY' },
  { :name => 'Haiti', :iso_two_letter_code => 'HT' },
  { :name => 'Heard and McDonald Islands', :iso_two_letter_code => 'HM' },
  { :name => 'Holy See (Vatican City State)', :iso_two_letter_code => 'VA' },
  { :name => 'Honduras', :iso_two_letter_code => 'HN' },
  { :name => 'Hong Kong', :iso_two_letter_code => 'HK' },
  { :name => 'Hungary', :iso_two_letter_code => 'HU' },
  { :name => 'Iceland', :iso_two_letter_code => 'IS' },
  { :name => 'India', :iso_two_letter_code => 'IN' },
  { :name => 'Indonesia', :iso_two_letter_code => 'ID' },
  { :name => 'Iran', :iso_two_letter_code => 'IR' },
  { :name => 'Iraq', :iso_two_letter_code => 'IQ' },
  { :name => 'Ireland', :iso_two_letter_code => 'IE' },
  { :name => 'Isle of Man', :iso_two_letter_code => 'IM' },
  { :name => 'Israel', :iso_two_letter_code => 'IL' },
  { :name => 'Italy', :iso_two_letter_code => 'IT' },
  { :name => 'Jamaica', :iso_two_letter_code => 'JM' },
  { :name => 'Japan', :iso_two_letter_code => 'JP' },
  { :name => 'Jersey', :iso_two_letter_code => 'JE' },
  { :name => 'Jordan', :iso_two_letter_code => 'JO' },
  { :name => 'Kazakhstan', :iso_two_letter_code => 'KZ' },
  { :name => 'Kenya', :iso_two_letter_code => 'KE' },
  { :name => 'Kiribati', :iso_two_letter_code => 'KI' },
  { :name => 'North Korea', :iso_two_letter_code => 'KP' },
  { :name => 'South Korea', :iso_two_letter_code => 'KR' },
  { :name => 'Kuwait', :iso_two_letter_code => 'KW' },
  { :name => 'Kyrgyzstan', :iso_two_letter_code => 'KG' },
  { :name => 'Laos', :iso_two_letter_code => 'LA' },
  { :name => 'Latvia', :iso_two_letter_code => 'LV' },
  { :name => 'Lebanon', :iso_two_letter_code => 'LB' },
  { :name => 'Lesotho', :iso_two_letter_code => 'LS' },
  { :name => 'Liberia', :iso_two_letter_code => 'LR' },
  { :name => 'Libya', :iso_two_letter_code => 'LY' },
  { :name => 'Liechtenstein', :iso_two_letter_code => 'LI' },
  { :name => 'Lithuania', :iso_two_letter_code => 'LT' },
  { :name => 'Luxembourg', :iso_two_letter_code => 'LU' },
  { :name => 'Macao', :iso_two_letter_code => 'MO' },
  { :name => 'Macedonia', :iso_two_letter_code => 'MK' },
  { :name => 'Madagascar', :iso_two_letter_code => 'MG' },
  { :name => 'Malawi', :iso_two_letter_code => 'MW' },
  { :name => 'Malaysia', :iso_two_letter_code => 'MY' },
  { :name => 'Maldives', :iso_two_letter_code => 'MV' },
  { :name => 'Mali', :iso_two_letter_code => 'ML' },
  { :name => 'Malta', :iso_two_letter_code => 'MT' },
  { :name => 'Marshall Islands', :iso_two_letter_code => 'MH' },
  { :name => 'Martinique', :iso_two_letter_code => 'MQ' },
  { :name => 'Mauritania', :iso_two_letter_code => 'MR' },
  { :name => 'Mauritius', :iso_two_letter_code => 'MU' },
  { :name => 'Mayotte', :iso_two_letter_code => 'YT' },
  { :name => 'Mexico', :iso_two_letter_code => 'MX' },
  { :name => 'Micronesia', :iso_two_letter_code => 'FM' },
  { :name => 'Moldova', :iso_two_letter_code => 'MD' },
  { :name => 'Monaco', :iso_two_letter_code => 'MC' },
  { :name => 'Mongolia', :iso_two_letter_code => 'MN' },
  { :name => 'Montenegro', :iso_two_letter_code => 'ME' },
  { :name => 'Montserrat', :iso_two_letter_code => 'MS' },
  { :name => 'Morocco', :iso_two_letter_code => 'MA' },
  { :name => 'Mozambique', :iso_two_letter_code => 'MZ' },
  { :name => 'Myanmar', :iso_two_letter_code => 'MM' },
  { :name => 'Namibia', :iso_two_letter_code => 'NA' },
  { :name => 'Nauru', :iso_two_letter_code => 'NR' },
  { :name => 'Nepal', :iso_two_letter_code => 'NP' },
  { :name => 'Netherlands', :iso_two_letter_code => 'NL' },
  { :name => 'Netherlands Antilles', :iso_two_letter_code => 'AN' },
  { :name => 'New Caledonia', :iso_two_letter_code => 'NC' },
  { :name => 'New Zealand', :iso_two_letter_code => 'NZ' },
  { :name => 'Nicaragua', :iso_two_letter_code => 'NI' },
  { :name => 'Niger', :iso_two_letter_code => 'NE' },
  { :name => 'Nigeria', :iso_two_letter_code => 'NG' },
  { :name => 'Niue', :iso_two_letter_code => 'NU' },
  { :name => 'Norfolk Island', :iso_two_letter_code => 'NF' },
  { :name => 'Northern Mariana Islands', :iso_two_letter_code => 'MP' },
  { :name => 'Norway', :iso_two_letter_code => 'NO' },
  { :name => 'Oman', :iso_two_letter_code => 'OM' },
  { :name => 'Pakistan', :iso_two_letter_code => 'PK' },
  { :name => 'Palau', :iso_two_letter_code => 'PW' },
  { :name => 'Palestinian Territory', :iso_two_letter_code => 'PS' },
  { :name => 'Panama', :iso_two_letter_code => 'PA' },
  { :name => 'Papua New Guinea', :iso_two_letter_code => 'PG' },
  { :name => 'Paraguay', :iso_two_letter_code => 'PY' },
  { :name => 'Peru', :iso_two_letter_code => 'PE' },
  { :name => 'Philippines', :iso_two_letter_code => 'PH' },
  { :name => 'Pitcairn', :iso_two_letter_code => 'PN' },
  { :name => 'Poland', :iso_two_letter_code => 'PL' },
  { :name => 'Portugal', :iso_two_letter_code => 'PT' },
  { :name => 'Puerto Rico', :iso_two_letter_code => 'PR' },
  { :name => 'Qatar', :iso_two_letter_code => 'QA' },
  { :name => 'Reunion', :iso_two_letter_code => 'RE' },
  { :name => 'Romania', :iso_two_letter_code => 'RO' },
  { :name => 'Russia', :iso_two_letter_code => 'RU' },
  { :name => 'Rwanda', :iso_two_letter_code => 'RW' },
  { :name => 'Saint Barthelemy', :iso_two_letter_code => 'BL' },
  { :name => 'Saint Helena', :iso_two_letter_code => 'SH' },
  { :name => 'Saint Kitts and Nevis', :iso_two_letter_code => 'KN' },
  { :name => 'Saint Lucia', :iso_two_letter_code => 'LC' },
  { :name => 'Saint Pierre and Miquelon', :iso_two_letter_code => 'PM' },
  { :name => 'Saint Vincent and the Grenadines', :iso_two_letter_code => 'VC' },
  { :name => 'Samoa', :iso_two_letter_code => 'WS' },
  { :name => 'San Marino', :iso_two_letter_code => 'SM' },
  { :name => 'Sao Tome and Principe', :iso_two_letter_code => 'ST' },
  { :name => 'Saudi Arabia', :iso_two_letter_code => 'SA' },
  { :name => 'Senegal', :iso_two_letter_code => 'SN' },
  { :name => 'Serbia', :iso_two_letter_code => 'RS' },
  { :name => 'Seychelles', :iso_two_letter_code => 'SC' },
  { :name => 'Sierra Leone', :iso_two_letter_code => 'SL' },
  { :name => 'Singapore', :iso_two_letter_code => 'SG' },
  { :name => 'Slovakia', :iso_two_letter_code => 'SK' },
  { :name => 'Slovenia', :iso_two_letter_code => 'SI' },
  { :name => 'Solomon Islands', :iso_two_letter_code => 'SB' },
  { :name => 'Somalia', :iso_two_letter_code => 'SO' },
  { :name => 'South Africa', :iso_two_letter_code => 'ZA' },
  { :name => 'South Georgia and the South Sandwich Islands', :iso_two_letter_code => 'GS' },
  { :name => 'Spain', :iso_two_letter_code => 'ES' },
  { :name => 'Sri Lanka', :iso_two_letter_code => 'LK' },
  { :name => 'Sudan', :iso_two_letter_code => 'SD' },
  { :name => 'Surinam', :iso_two_letter_code => 'SR' },
  { :name => 'Svalbard and Jan Mayen', :iso_two_letter_code => 'SJ' },
  { :name => 'Swaziland', :iso_two_letter_code => 'SZ' },
  { :name => 'Sweden', :iso_two_letter_code => 'SE' },
  { :name => 'Switzerland', :iso_two_letter_code => 'CH' },
  { :name => 'Syria', :iso_two_letter_code => 'SY' },
  { :name => 'Taiwan', :iso_two_letter_code => 'TW' },
  { :name => 'Tajikistan', :iso_two_letter_code => 'TJ' },
  { :name => 'Tanzania', :iso_two_letter_code => 'TZ' },
  { :name => 'Thailand', :iso_two_letter_code => 'TH' },
  { :name => 'Timor-Leste', :iso_two_letter_code => 'TL' },
  { :name => 'Togo', :iso_two_letter_code => 'TG' },
  { :name => 'Tokelau', :iso_two_letter_code => 'TK' },
  { :name => 'Tonga', :iso_two_letter_code => 'TO' },
  { :name => 'Trinidad and Tobago', :iso_two_letter_code => 'TT' },
  { :name => 'Tunisia', :iso_two_letter_code => 'TN' },
  { :name => 'Turkey', :iso_two_letter_code => 'TR' },
  { :name => 'Turkmenistan', :iso_two_letter_code => 'TM' },
  { :name => 'Turks and Caicos Islands', :iso_two_letter_code => 'TC' },
  { :name => 'Tuvalu', :iso_two_letter_code => 'TV' },
  { :name => 'Uganda', :iso_two_letter_code => 'UG' },
  { :name => 'Ukraine', :iso_two_letter_code => 'UA' },
  { :name => 'UAE', :iso_two_letter_code => 'AE' },
  { :name => 'United Kingdom', :iso_two_letter_code => 'GB' },
  { :name => 'United States', :iso_two_letter_code => 'US' },
  { :name => 'United States Minor Outlying Islands', :iso_two_letter_code => 'UM' },
  { :name => 'Uruguay', :iso_two_letter_code => 'UY' },
  { :name => 'Uzbekistan', :iso_two_letter_code => 'UZ' },
  { :name => 'Vanuatu', :iso_two_letter_code => 'VU' },
  { :name => 'Venezuela', :iso_two_letter_code => 'VE' },
  { :name => 'Vietnam', :iso_two_letter_code => 'VN' },
  { :name => 'British Virgin Islands', :iso_two_letter_code => 'VG' },
  { :name => 'US Virgin Islands', :iso_two_letter_code => 'VI' },
  { :name => 'Wallis and Futuna', :iso_two_letter_code => 'WF' },
  { :name => 'Western Sahara', :iso_two_letter_code => 'EH' },
  { :name => 'Yemen', :iso_two_letter_code => 'YE' },
  { :name => 'Zambia', :iso_two_letter_code => 'ZM' },
  { :name => 'Zimbabwe', :iso_two_letter_code => 'ZW' }  
].each do |c|
  Country.find_or_create_by_name(:name => c[:name], :iso_two_letter_code => c[:iso_two_letter_code])
end

Let me know if you have any improvements, but it’s pretty much taken directly from the ISO website.

No TweetBacks yet. (Be the first to Tweet this post)
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • MySpace
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis

If you enjoyed this post, make sure you subscribe to my RSS feed!

This entry was posted in Software and tagged , , , . Bookmark the permalink. Both comments and trackbacks are currently closed.

3 Comments

  1. Posted August 28, 2010 at 6:05 pm | Permalink

    Awesome. Thanks so much for posting this!

  2. DavyB
    Posted November 12, 2010 at 6:28 pm | Permalink

    the ISO (International Standards Organisation) are always the best source for this kind of information. People should always be aware that if someone is offering a paid for solution for this kind of data, invariably the data is available elsewhere for free.
    However there are still anomalies in this data
    eg1) according to the ISO data the country code for the United Kingdom is GB however there are no websites in the .GB domain (there used to be a mere handful of .mod.gb the UK equvalent of the USA .mil domain) we actually use .UK predominately .co.uk.
    eg2) the .SU domain still lives on, most should be in .RU
    eg3) You would never get the international domains used in the USA .com etc to move to the .us domain where they should in theory be.

  3. Posted November 10, 2011 at 1:35 pm | Permalink

    Awesome tip. You’re right – I don’t think most people knew about this. I certainly didn’t!