Search code examples
ruby-on-railsruby-on-rails-4rubygemscountries

How to use the Countries gem


I am trying to use the Countries Gem, but had some basic questions on how to incorporate this gem after I've bundle-installed it.

  1. Do I need to create a new controller/model to access the countries?
  2. How do I create a simple select drop-down to show a list of countries for a user to select?
  3. Where are all the countries stored? (I saw the data file in the Gem, but need some clarity how to bring that into my own app)

Solution

  • 1) You don't need a new controller/model to access the countries

    2) There is an example app on the README page which shows you how to use forms and dropdowns.

    3) The countries are stores within the app. I believe country_select includes the ISO 3166 gem to get the list of countries. You can view the data in the countries.yaml file

    If want to know anything else, I recommend looking at the example app. It provides a good example of how to use the gem.