New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rails-countries

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rails-countries

  • 1.2.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

rails-countries

Integration between Rails and countries gem.

Gem Version Gem license

Installation

Add this line to your application's Gemfile:

gem 'rails-countries'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rails-countries

Usage

ActiveRecord models

class Person < ActiveRecord::Base
  validates :my_attribute, countries_alpha2: true
  # or
  validates_countries_alpha2_of :my_attribute

  validates :another_attribute, countries_alpha3: true
  # or
  validates_countries_alpha3_of :another_attribute
end

Plain Old Ruby Objects

class Person
  include ActiveModel::Model

  validates :my_attribute, countries_alpha2: true
  # or
  validates_countries_alpha2_of :my_attribute

  validates :another_attribute, countries_alpha3: true
  # or
  validates_countries_alpha3_of :another_attribute
end

Views

Helpers
<%= i18n_country_name_by_alpha2('US') %>
<%= i18n_country_name_by_alpha2('US', 'pt-BR') %>

<%= i18n_country_name_by_alpha3('USA') %>
<%= i18n_country_name_by_alpha3('USA', 'pt-BR') %>
Rails Form helpers
<%= select_tag(:my_attribute, countries_alpha2_options) %>
<%= select_tag(:my_attribute, countries_alpha2_options('pt-BR')) %>

<%= select_tag(:another_attribute, countries_alpha3_options) %>
<%= select_tag(:another_attribute, countries_alpha3_options('pt-BR')) %>
SimpleForm
<%= f.input :my_attribute, collection: countries_alpha2_options %>
<%= f.input :my_attribute, collection: countries_alpha2_options('pt-BR') %>

<%= f.input :my_attribute, collection: countries_alpha3_options %>
<%= f.input :my_attribute, collection: countries_alpha3_options('pt-BR') %>

I18n

To customize your error messages you can create a locale file like this:

en:
  errors:
    messages:
      countries_alpha2_invalid: '%{alpha2} is not valid'
      countries_alpha3_invalid: '%{alpha3} is not valid'

Contribute it!

Help us to improve the features and translations of this gem! Your contribution will be welcome :tada:

FAQs

Package last updated on 23 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc