Class: ActiveModel::Validations::ConfirmationValidator
- Inherits:
-
EachValidator
- Object
- ActiveModel::Validator
- EachValidator
- ActiveModel::Validations::ConfirmationValidator
- Defined in:
- lib/active_model/validations/confirmation.rb
Overview
:nodoc:
Instance Attribute Summary
Attributes inherited from EachValidator
Attributes inherited from ActiveModel::Validator
Instance Method Summary collapse
Methods inherited from EachValidator
#check_validity!, #initialize, #validate
Methods inherited from ActiveModel::Validator
#initialize, kind, #kind, #validate
Constructor Details
This class inherits a constructor from ActiveModel::EachValidator
Instance Method Details
#setup(klass) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/active_model/validations/confirmation.rb', line 12 def setup(klass) klass.send(:attr_reader, *attributes.map do |attribute| :"#{attribute}_confirmation" unless klass.method_defined?(:"#{attribute}_confirmation") end.compact) klass.send(:attr_writer, *attributes.map do |attribute| :"#{attribute}_confirmation" unless klass.method_defined?(:"#{attribute}_confirmation=") end.compact) end |
#validate_each(record, attribute, value) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/active_model/validations/confirmation.rb', line 5 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 |