Class: Mongoid::Validations::PresenceValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- Mongoid::Validations::PresenceValidator
- Defined in:
- lib/mongoid/validations/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 |
# File 'lib/mongoid/validations/presence.rb', line 28 def validate_each(document, attribute, value) field = document.fields[attribute.to_s] if field.try(:localized?) && !value.blank? value.each_pair do |locale, value| document.errors.add(attribute, :blank_on_locale, .merge(:location => locale)) if value.blank? end elsif document.relations.has_key?(attribute.to_s) if value.blank? && document.send(attribute).blank? document.errors.add(attribute, :blank, ) end else document.errors.add(attribute, :blank, ) if value.blank? end end |