1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Refactoring conditional logic

Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
Subba Rao Pasupuleti 2010-08-31 17:57:39 -04:00 committed by José Valim
parent 2d74ed49f4
commit 0ae81a2124

View file

@ -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
end
def setup(klass)