Type:
Module

Active Model Validations

Provides a full validation framework to your objects.

A minimal implementation could be:

class Person
  include ActiveModel::Validations

  attr_accessor :first_name, :last_name

  validates_each :first_name, :last_name do |record, attr, value|
    record.errors.add attr, 'starts with z.' if value.to_s[0] == ?z
  end
end

Which provides you with the full standard validation stack that you know from Active Record:

person = Person.new
person.valid?                   # => true
person.invalid?                 # => false

person.first_name = 'zoolander'
person.valid?                   # => false
person.invalid?                 # => true
person.errors.messages          # => {first_name:["starts with z."]}

Note that ActiveModel::Validations automatically adds an errors method to your instances initialized with a new ActiveModel::Errors object, so there is no need for you to do this manually.

Active Model Length Validator

valid?

valid?(context = nil) Instance Public methods Runs all the specified validations

2015-06-20 00:00:00
validates_with

validates_with(*args, &block) Instance Public methods Passes the record

2015-06-20 00:00:00
invalid?

invalid?(context = nil) Instance Public methods Performs the opposite of valid

2015-06-20 00:00:00
errors

errors() Instance Public methods Returns the Errors object that

2015-06-20 00:00:00