https://github.com/pedrofurtado/validates-correios-cep
Brazilian zipcode validation for ActiveRecord, integrated with correios-cep gem.
https://github.com/pedrofurtado/validates-correios-cep
activemodel activerecord cep prodis rails
Last synced: 3 months ago
JSON representation
Brazilian zipcode validation for ActiveRecord, integrated with correios-cep gem.
- Host: GitHub
- URL: https://github.com/pedrofurtado/validates-correios-cep
- Owner: pedrofurtado
- License: mit
- Created: 2017-04-30T23:54:31.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-08-04T01:25:47.000Z (almost 5 years ago)
- Last Synced: 2025-12-06T06:04:05.916Z (6 months ago)
- Topics: activemodel, activerecord, cep, prodis, rails
- Language: Ruby
- Homepage: https://rubygems.org/gems/validates-correios-cep
- Size: 20.5 KB
- Stars: 6
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# validates-correios-cep
[](https://badge.fury.io/rb/validates-correios-cep)
[]()
[](https://github.com/pedrofurtado/validates-correios-cep/actions/workflows/ci.yml)
[]()
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'validates-correios-cep'
```
And then execute:
$ bundle install
Or install it yourself as:
$ gem install validates-correios-cep
## Usage
### ActiveRecord models
```ruby
class Person < ActiveRecord::Base
validates :my_attribute, correios_cep: true
# or
validates_correios_cep_of :my_attribute
end
```
### Plain Old Ruby Objects
```ruby
class Person
include ActiveModel::Model
validates :my_attribute, correios_cep: true
# or
validates_correios_cep_of :my_attribute
end
```
## I18n
To customize your error messages you can create a locale file like this:
```yaml
en:
correios_cep:
errors:
messages:
not_exists: '%{zipcode} is not a existent Brazilian zipcode'
connection_failed: 'failure on connection with Brazilian Correios API'
invalid: '%{zipcode} is not a valid Brazilian zipcode'
timeouted: 'timeout with Brazilian Correios API'
```
The %{zipcode} contains the zipcode value, filled by user.
## Something wrong with the translations? Contribute it!
Send a pull request! Fix the translations or create it for some missing locale. Help us to improves the quality of translations!