module ActiveModel::Validations
def errors
def errors @errors ||= Errors.new(self) end
def invalid?(context = nil)
Performs the opposite of valid?. Returns true if errors were added,
def invalid?(context = nil) !valid?(context) end
def run_validations!
def run_validations! _run_validate_callbacks errors.empty? end
def valid?(context = nil)
otherwise false. Context can optionally be supplied to define which callbacks
Runs all the specified validations and returns true if no errors were added
def valid?(context = nil) current_context, self.validation_context = validation_context, context errors.clear run_validations! ensure self.validation_context = current_context end
def validates_with(*args, &block)
class version of this method for more information
to the class and available as options, please refer to the
If you pass any additional configuration options, they will be passed
in the callback
placed on the validates method as these are applied and tested
available on the class version of validates_with, should instead be
Standard configuration options (:on, :if and :unless), which are
end
end
validates_with MyValidator, MyOtherValidator
def instance_validations
validates :instance_validations, :on => :create
include ActiveModel::Validations
class Person
You may also pass it multiple classes, like so:
creating your own validator.
Please consult the class method documentation for more information on
end
end
validates_with MyValidator
def instance_validations
validates :instance_validations
include ActiveModel::Validations
class Person
to add errors based on more complex conditions.
Passes the record off to the class or classes specified and allows them
def validates_with(*args, &block) options = args.extract_options! args.each do |klass| validator = klass.new(options, &block) validator.validate(self) end end