Methods
Included Modules
Public Instance methods
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.
[ show source ]
# File activerecord/lib/active_record/validations.rb, line 42 def save(options={}) perform_validations(options) ? super : false end
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.
[ show source ]
# File activerecord/lib/active_record/validations.rb, line 48 def save!(options={}) perform_validations(options) ? super : raise(RecordInvalid.new(self)) end
Runs all the specified validations and returns true if no errors were added otherwise false.
[ show source ]
# 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
[ show source ]
# 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