Class: Mongoid::Validatable::PresenceValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- Mongoid::Validatable::PresenceValidator
- Defined in:
- lib/mongoid/validatable/presence.rb
Overview
Validates that the specified attributes are not blank (as defined by Object#blank?).
Instance Method Summary collapse
-
#validate_each(document, attribute, value) ⇒ Object
Validate the document for the attribute and value.
Instance Method Details
#validate_each(document, attribute, value) ⇒ Object
Validate the document for the attribute and value.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mongoid/validatable/presence.rb', line 28 def validate_each(document, attribute, value) field = document.fields[document.database_field_name(attribute)] if field.try(:localized?) && !value.blank? value.each_pair do |_locale, _value| document.errors.add( attribute, :blank_in_locale, **.merge(location: _locale) ) if not_present?(_value) end elsif document.relations.has_key?(attribute.to_s) if relation_or_fk_missing?(document, attribute, value) document.errors.add(attribute, :blank, **) end else document.errors.add(attribute, :blank, **) if not_present?(value) end end |