- Modeled after ActiveRecord::Validations::UniquenessValidator
- Only supports uniqueness for attributes, not associations.
- Because indexing can vary, only supports one attribute at a time. Defaults to the :symbol indexer (*_ssim). Index field can be declared explicitly with :index_field option, or implicitly with :index_type and :data_type options.
- Designed for single-valued attributes, i.e.,
:multiple => false
. Should work for multi-valued attributes having single value; may work (perhaps not exactly as desired) for attributes having multiple values. - Does not support scoping or extra conditions.
- Save
uniqueness_validator.rb
inapp/validators/
. - If you want the
validates_uniqueness_of
convenience method, include theValidations
mixin in your model.
See the spec test module.
You should use the predefined :taken error message instead of hard-coding the error string. We did this based upon the activerecord uniqueness validator:
https://github.com/avalonmediasystem/avalon/blob/develop/app/validators/uniqueness_validator.rb#L28
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/validations/uniqueness.rb#L25-L28