Gem Countries – Support for getting information related to Country

Tram Ho

1. Introduction

When working on projects, we sometimes face problems related to information of different countries. And of course, you can search google for the information of the country you need and add it to your project yourself. However, this will take a lot of your time.

To solve this problem, today I will introduce you to gem countries

It is a collection of all the useful information of every country in ISO 3166 . It contains information:

From the above information, we have basically solved the National issues in our project.

2. Install

  • Method 1: gem install countries
  • Method 2: Add to Gemfile:

    and run

3. Get the information of the Country

The first is to initialize the Country object and from there you can get other information related to this Country

3.1 Country code

Usually use the following 2 types: alpha2, alpha3

3.2 Name

3.3 Location

Information related to location

3.4 District / State Information

3.5 Timezone (optional)

To determine the timezone, it is necessary to install additional gem tzinfo gem countries because gem countries do not support this part

After installation we can get the following common information:

3.6 Information about phone number

Conclude

Because it is a specific type of spec related to Country. So you probably won’t find it necessary to use it. But hopefully remember the key word gem countries to need when needed. Can find this support gem quickly.

References

https://github.com/hexorx/countries

Share the news now

Source : Viblo