Provides a simple helper to get an HTML select list of countries. The list of countries comes from the ISO 3166 standard. While it is a relatively neutral source of country names, it will still offend some users.
Users are strongly advised to evaluate the suitability of this list given their user base.
To output a drop-down menu of all countries, with Australia and New Zealand at the top:
country_select(:user, :country, ["AU", "NZ"], :prompt => true, :value => user.country)
This version supports saving the country abbreviation in the database, and has abstracted the list of countries out into a Geography module. This way, you can use this list in your models:
class Address < ActiveRecord::Base validates_inclusion_of :country_code, :in => Geography::country_codes def country_name Geography::country_name_from_code( country_code ) end end
Code by Michael Koziarski, Jim Benton, Arthur Gunn.
Released under the MIT license