module
ActiveModel::Validations
v3.2.1 -
Show latest stable
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 Presence Validator
Active Model Exclusion Validator
Active Model Format Validator
Active Model validates method
Active Model Inclusion Validator
Active Model Length Validator
Active Model Numericality Validator
Active Model Confirmation Validator
Included modules
- ActiveModel::Validations::HelperMethods
- ActiveSupport::Callbacks
Files
- activemodel/lib/active_model/validations.rb
- activemodel/lib/active_model/validations/acceptance.rb
- activemodel/lib/active_model/validations/callbacks.rb
- activemodel/lib/active_model/validations/confirmation.rb
- activemodel/lib/active_model/validations/exclusion.rb
- activemodel/lib/active_model/validations/format.rb
- activemodel/lib/active_model/validations/inclusion.rb
- activemodel/lib/active_model/validations/length.rb
- activemodel/lib/active_model/validations/numericality.rb
- activemodel/lib/active_model/validations/presence.rb
- activemodel/lib/active_model/validations/validates.rb
- activemodel/lib/active_model/validations/with.rb
Nested classes and modules
- ActiveModel::Validations::AcceptanceValidator
- ActiveModel::Validations::Callbacks
- ActiveModel::Validations::ClassMethods
- ActiveModel::Validations::ConfirmationValidator
- ActiveModel::Validations::ExclusionValidator
- ActiveModel::Validations::FormatValidator
- ActiveModel::Validations::HelperMethods
- ActiveModel::Validations::InclusionValidator
- ActiveModel::Validations::LengthValidator
- ActiveModel::Validations::NumericalityValidator
- ActiveModel::Validations::PresenceValidator