Class: Devise::Orm::DataMapper::UniquenessValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- Devise::Orm::DataMapper::UniquenessValidator
- Defined in:
- lib/devise/orm/data_mapper/validations/active_model.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(target, attribute, value) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/devise/orm/data_mapper/validations/active_model.rb', line 23 def validate_each(target, attribute, value) resource = ::DataMapper.repository(target.repository.name) { target.model.first(attribute => value) } if resource.nil? || (target.saved? && resource.key == target.key) return true else target.errors.add(attribute, :taken) return false end end |