Methods
Included Modules
Public Instance methods
save(options={})

The validation process on save can be skipped by passing false. The regular Base#save method is replaced with this when the validations module is mixed in, which it is by default.

  # File activerecord/lib/active_record/validations.rb, line 42
def save(options={})
  perform_validations(options) ? super : false
end
save!(options={})

Attempts to save the record just like Base#save but will raise a RecordInvalid exception instead of returning false if the record is not valid.

  # File activerecord/lib/active_record/validations.rb, line 48
def save!(options={})
  perform_validations(options) ? super : raise(RecordInvalid.new(self))
end
valid?(context = nil)

Runs all the specified validations and returns true if no errors were added otherwise false.

  # File activerecord/lib/active_record/validations.rb, line 53
def valid?(context = nil)
  context ||= (new_record? ? :create : :update)
  output = super(context)

  deprecated_callback_method(:validate)
  deprecated_callback_method(:"validate_on_#{context}")

  errors.empty? && output
end
Protected Instance methods
perform_validations(options={})
  # File activerecord/lib/active_record/validations.rb, line 65
def perform_validations(options={})
  perform_validation = case options
  when Hash
    options[:validate] != false
  else
    ActiveSupport::Deprecation.warn "save(#{options}) is deprecated, please give save(:validate => #{options}) instead", caller
    options
  end

  if perform_validation
    valid?(options.is_a?(Hash) ? options[:context] : nil)
  else
    true
  end
end