Included Modules

Files

Class Index [+]

Quicksearch

ActiveRecord::Validations

Public Instance Methods

save(options={}) click to toggle source

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 lib/active_record/validations.rb, line 42
42:     def save(options={})
43:       perform_validations(options) ? super : false
44:     end
save!(options={}) click to toggle source

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 lib/active_record/validations.rb, line 48
48:     def save!(options={})
49:       perform_validations(options) ? super : raise(RecordInvalid.new(self))
50:     end
valid?(context = nil) click to toggle source

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

    # File lib/active_record/validations.rb, line 53
53:     def valid?(context = nil)
54:       context ||= (new_record? ? :create : :update)
55:       output = super(context)
56: 
57:       deprecated_callback_method(:validate)
58:       deprecated_callback_method(:"validate_on_#{context}")
59: 
60:       errors.empty? && output
61:     end

Protected Instance Methods

perform_validations(options={}) click to toggle source
    # File lib/active_record/validations.rb, line 65
65:     def perform_validations(options={})
66:       perform_validation = case options
67:       when Hash
68:         options[:validate] != false
69:       else
70:         ActiveSupport::Deprecation.warn "save(#{options}) is deprecated, please give save(:validate => #{options}) instead", caller
71:         options
72:       end
73: 
74:       if perform_validation
75:         valid?(options.is_a?(Hash) ? options[:context] : nil)
76:       else
77:         true
78:       end
79:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.