Skip to content

Instantly share code, notes, and snippets.

@ivan22
Created May 17, 2014 03:17
Show Gist options
  • Select an option

  • Save ivan22/23cfdef59e8661ca8b4c to your computer and use it in GitHub Desktop.

Select an option

Save ivan22/23cfdef59e8661ca8b4c to your computer and use it in GitHub Desktop.
Country gem

Gemfile

gem 'countries'

View

= select_tag(:country, options_for_select(Country.all))
Country[user.citizenship].nationality
Country[user.country].name # gives the country name

Draw nationalities

  • Note that some countries don't have nationalities...
  • Note that some countries share the same nationalities...
nationalities = Country.all do |country|
      country = Country[country.first] # it's weird but that's the way it is...
      country.nationality.present? ? [country.nationality, country.alpha2] : [country.name, country.alpha2]
    end

@nationalities_options = nationalities.sort { |a,b| a[0] <=> b[0] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment