Validations
MongoMapper uses ActiveModel:Validations, so it works almost exactly like ActiveRecord.
Validations are run when attempting to save a record. If validations fail, save will return false
.
Shorthand
Most simple validations can be declared along with the keys.
The available options when defining keys are:
- :required - Boolean that declares
validates_presence_of
- :unique - Boolean that declares
validates_uniqueness_of
- :numeric - Boolean that declares
validates_numericality_of
- :format - Regexp that is passed to
validates_format_of
- :in - Array that is passed to
validates_inclusion_of
- :not_in - Array that is passed to
validates_exclusion_of
- :length - Integer, Range, or Hash that is passed to
validates_length_of