Module: Devise::Orm::MongoMapper::ActiveModelCompatibility

Defined in:
lib/devise/orm/mongo_mapper_active_model.rb

Overview

class UniquenessValidator < ActiveModel::EachValidator

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

end

Instance Method Summary collapse

Instance Method Details

#save(*args) ⇒ Object

include ActiveModel::Validations does not make save check valid?. This may not be the best solution, but it seems to work. Note that Compatibility is included after this module; its #save method handles the :validate => false option.



49
50
51
52
53
# File 'lib/devise/orm/mongo_mapper_active_model.rb', line 49

def save(*args)
  retval = valid? && super(*args)
  assert_save_successful(:save, retval)
  retval
end