Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
48 lines (33 sloc) 1.53 KB

CountriesList gem

A gem that maintains a list of country codes to country names. Supports i18n of country names. Provides built-in helpers for generating select tags of country names for and standard rails form helpers.

This gem comes with a list of countries built in, but you can provide a custom YML file of country code to country names.


gem "countries_list"


CountriesList works out of the box. The below is optional.

CountriesList.configure do |config|
  config.locale = :en # Use english country names (default)
  config.priority = [:us, :ca, :au] # Copy these countries to the top of the list

# Provide a custom list of countries
CountriesList.configure do |config|
  config.locale = :fr
  config.file_path = File.join(Rails.root.to_s, "config", "locales", "countries_fr.yml")


# Fetch all countries
CountriesList.all # Also, CountriesList.find(:all)

# Fetch a specific country
us = CountriesList.find(:us)
ca = CountriesList.find("ca")
au = CountriesList.find("AU")

# In views. This behaves just like select() but you do not have to specificy the options
<%= country_select("user", "country_code") %>

# With a default value
<%= country_select("user", "country_code", {:value => "US"})


  • Add formtastic input class
  • Add formtastic example
  • Support more languages than just en US
  • Increase test coverage. Specifically with rails integration