module TopModel::Validations::ClassMethods

Public Instance Methods

validates_uniqueness_of(*attr_names) click to toggle source

Validates that the specified attribute is unique.

class Person < ActiveRecord::Base
  validates_uniquness_of :essay
end

Configuration options:

  • :allow_nil - Attribute may be nil; skip validation.

  • :allow_blank - Attribute may be blank; skip validation.

  • :message - The error message to use for a :minimum, :maximum, or :is violation. An alias of the appropriate too_long/too_short/wrong_length message.

  • :on - Specifies when this validation is active (default is :save, other options :create, :update).

  • :if - Specifies a method, proc or string to call to determine if the validation should occur (e.g. :if => :allow_validation, or :if => Proc.new { |user| user.signup_step > 2 }). The method, proc or string should return or evaluate to a true or false value.

  • :unless - Specifies a method, proc or string to call to determine if the validation should not occur (e.g. :unless => :skip_validation, or :unless => Proc.new { |user| user.signup_step <= 2 }). The method, proc or string should return or evaluate to a true or false value.

# File lib/topmodel/validations/uniqueness.rb, line 35
def validates_uniqueness_of(*attr_names)
  validates_with UniquenessValidator, _merge_attributes(attr_names)
end