module ActiveModel::Validations
def valid?(context = nil)
person.valid? # => true
person = Person.new
end
validates_presence_of :name, on: :new
attr_accessor :name
include ActiveModel::Validations
class Person
against (the context is defined on the validations using :on).
Context can optionally be supplied to define which callbacks to test
person.valid? # => true
person.name = 'david'
person.valid? # => false
person.name = ''
person = Person.new
end
validates_presence_of :name
attr_accessor :name
include ActiveModel::Validations
class Person
added otherwise +false+.
Runs all the specified validations and returns +true+ if no errors were
def valid?(context = nil) current_context = validation_context context_for_validation.context = context errors.clear run_validations! ensure context_for_validation.context = current_context end