Module: ActiveRecord::Validations::ClassMethods

Defined in:
lib/active_record/validations/globalized_uniqueness.rb

Instance Method Summary collapse

Instance Method Details

#validates_globalized_uniqueness_of(*attr_names) ⇒ Object

Validates whether the value of the specified attributes are unique across the system. Useful for making sure that only one user can be named “davidhh”.

See validates_uniqueness_of in ActiveRecord::Validations::ClassMethods for further explanation.

This validator works the same, but additionally respects globalize3 model translations. Also, you can use :locale as value for :scope.

For instance, if you want to validate that a product title is unique in each locale:

class Product < ActiveRecord::Base
  translates :title

  validates_globalized_uniqueness_of :title, :scope => :locale
end


129
130
131
# File 'lib/active_record/validations/globalized_uniqueness.rb', line 129

def validates_globalized_uniqueness_of(*attr_names)
  validates_with GlobalizedUniquenessValidator, _merge_attributes(attr_names)
end