Module: ActiveModel::Validations::ClassMethods

Defined in:
lib/validates_as_email.rb

Instance Method Summary collapse

Instance Method Details

#validates_as_email(*attr_names) ⇒ Object

Validates that the specified attribute is a valid email address.

Configuration options:

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

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

  • :message - The error message to be displayed

  • :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.



53
54
55
# File 'lib/validates_as_email.rb', line 53

def validates_as_email(*attr_names)
  validates_with EmailValidator, _merge_attributes(attr_names)
end