Class: ActiveModel::Validations::ConfirmationValidator
- Inherits:
-
EachValidator
- Object
- ActiveModel::Validator
- EachValidator
- ActiveModel::Validations::ConfirmationValidator
- Defined in:
- activemodel/lib/active_model/validations/confirmation.rb
Overview
:nodoc:
Instance Attribute Summary
Attributes inherited from EachValidator
Attributes inherited from ActiveModel::Validator
Instance Method Summary collapse
-
#initialize(options) ⇒ ConfirmationValidator
constructor
A new instance of ConfirmationValidator.
- #validate_each(record, attribute, value) ⇒ Object
Methods inherited from EachValidator
Methods inherited from ActiveModel::Validator
Constructor Details
#initialize(options) ⇒ ConfirmationValidator
Returns a new instance of ConfirmationValidator.
5 6 7 8 |
# File 'activemodel/lib/active_model/validations/confirmation.rb', line 5 def initialize() super setup!([:class]) end |
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
10 11 12 13 14 15 |
# File 'activemodel/lib/active_model/validations/confirmation.rb', line 10 def validate_each(record, attribute, value) if (confirmed = record.send("#{attribute}_confirmation")) && (value != confirmed) human_attribute_name = record.class.human_attribute_name(attribute) record.errors.add(:"#{attribute}_confirmation", :confirmation, .merge(attribute: human_attribute_name)) end end |