Class: NotEqualsValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- NotEqualsValidator
- Defined in:
- lib/validators/not_equals_validator.rb
Overview
Checks a value not equals to another attribute’s one.
validates :password, not_equals_to: :login
Use the :allow_nil
key to skip validation in case the attribute value isn’t set.
validates :password, not_equals_to: :login, allow_nil: true
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/validators/not_equals_validator.rb', line 15 def validate_each(record, attribute, value) return if value.nil? && [:allow_nil] if value == record.send([:to]) record.errors.add attribute, :not_equals end end |