Browse files

Refactoring conditional logic

Signed-off-by: José Valim <>
  • Loading branch information...
1 parent 2d74ed4 commit 0ae81a21243961f4d2481e9b87e3c807291d21a9 @subbarao subbarao committed with josevalim Aug 31, 2010
Showing with 3 additions and 3 deletions.
  1. +3 −3 activemodel/lib/active_model/validations/confirmation.rb
@@ -4,9 +4,9 @@ module ActiveModel
module Validations
class ConfirmationValidator < EachValidator
def validate_each(record, attribute, value)
- confirmed = record.send(:"#{attribute}_confirmation")
- return if confirmed.nil? || value == confirmed
- record.errors.add(attribute, :confirmation, options)
+ if (confirmed = record.send("#{attribute}_confirmation")) && (value != confirmed)
+ record.errors.add(attribute, :confirmation, options)
+ end
def setup(klass)

4 comments on commit 0ae81a2


bcardarella replied Nov 5, 2012

This doesn't work. If you have the case of password and password_confirmation

If password is set to 'test' and password_confirmation is nil you will not get an error message. It should be reverted to the previous logic


bcardarella replied Nov 5, 2012


josevalim replied Nov 13, 2012

@bcardarella the previous code did not validate if the confirmation is nil as well. This is by design and is how confirmation behaves for a long time. We have written about it some time ago:


bcardarella replied Nov 13, 2012

Right but now that the validation is reversed I believe the logic needs to change

Please sign in to comment.