module Validations
Ruby on Rails 3.0.20
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 # => #<OrderedHash {: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 Acceptance Validator
Active Model Confirmation Validator
Active Model Exclusion Validator
Active Model Format Validator
Active Model Inclusion Validator
Active Model Length Validator
Active Model Numericality Validator
Active Model Presence Validator
Active Model validates method
Namespace
Modules
- ActiveModel::Validations::Callbacks
- ActiveModel::Validations::ClassMethods
- ActiveModel::Validations::HelperMethods
Classes
- ActiveModel::Validations::AcceptanceValidator
- ActiveModel::Validations::ConfirmationValidator
- ActiveModel::Validations::ExclusionValidator
- ActiveModel::Validations::FormatValidator
- ActiveModel::Validations::InclusionValidator
- ActiveModel::Validations::LengthValidator
- ActiveModel::Validations::NumericalityValidator
- ActiveModel::Validations::PresenceValidator
Includes
Extends
Attributes
Methods (defined here)
- # errors
- # invalid?
- # run_validations!
- # valid?
- # validates_with
Used by
Included by (1)
Methods (inherited)
From ActiveModel::Translation
(4)
From ActiveModel::Validations::HelperMethods
(9)
From ActiveSupport::Callbacks
(2)
From ActiveSupport::Concern
(3)
- # append_features
- # included
- self. extended
From ActiveModel::Naming
(5)
- # model_name
- self. model_name_from_record_or_class
- self. plural
- self. singular
- self. uncountable?
From ActiveSupport::DescendantsTracker
(6)
- # descendants
- # direct_descendants
- # inherited
- self. clear
- self. descendants
- self. direct_descendants