Simple EachValidator with localization support
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.document
.gitignore
.rspec
.ruby-gemset
.ruby-version
Gemfile
Gemfile.lock
LICENSE
README.md
Rakefile
VERSION
localized_each_validator.gemspec

README.md

Localized EachValidator

Author Tim Morgan
Version 1.0.3 (Jul 23, 2013)
License Released under the MIT license.

About

Localized EachValidator is a subclass of ActiveRecord's EachValidator that makes it easier to write a localized validator with Rails 3's localization. It's small and simple.

Usage

Add this gem to your project's Gemfile, or to your own validator gem's dependencies. Then, sublass LocalizedEachValidator and provide the error_key and override the valid? method, like so:

class FourValidator < ActiveRecord::EachValidator
  error_key :must_be_four

  def valid?(record, field, value)
    value == 4
  end

Now, users of your validator can create a localization YAML file like so:

en:
  activerecord:
    errors:
      messages:
        must_be_four: This number must be four.

See the {LocalizedEachValidator} class documentation for more information.