Module: ActiveRecord::Validations
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::Validations
- Defined in:
- activerecord/lib/active_record/validations.rb,
activerecord/lib/active_record/validations/associated.rb,
activerecord/lib/active_record/validations/uniqueness.rb
Defined Under Namespace
Modules: ClassMethods Classes: AssociatedValidator, UniquenessValidator
Instance Method Summary (collapse)
-
- (Object) save(options = {})
The validation process on save can be skipped by passing false.
-
- (Object) 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.
-
- (Boolean) valid?(context = nil)
Runs all the specified validations and returns true if no errors were added otherwise false.
Methods included from ActiveSupport::Concern
append_features, extended, included
Methods included from ActiveModel::Validations
#errors, #invalid?, #validates_with
Methods included from ActiveSupport::Callbacks
Instance Method Details
- (Object) 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.
42 43 44 |
# File 'activerecord/lib/active_record/validations.rb', line 42 def save(={}) perform_validations() ? super : false end |
- (Object) 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.
48 49 50 |
# File 'activerecord/lib/active_record/validations.rb', line 48 def save!(={}) perform_validations() ? super : raise(RecordInvalid.new(self)) end |
- (Boolean) valid?(context = nil)
Runs all the specified validations and returns true if no errors were added otherwise false.
53 54 55 56 57 58 59 60 61 |
# 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 |