aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-08-10 15:24:48 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-08-10 15:24:48 +0100
commite202c6c814886251d3c7a9b6a33ba6a8f1a2d448 (patch)
tree778acbfa61bbd227cdbba9ebd719b9c567c3b807 /activemodel
parentcccb0e6b9327fb562b72007a012933c9c61a33fa (diff)
downloadrails-e202c6c814886251d3c7a9b6a33ba6a8f1a2d448.tar.gz
rails-e202c6c814886251d3c7a9b6a33ba6a8f1a2d448.tar.bz2
rails-e202c6c814886251d3c7a9b6a33ba6a8f1a2d448.zip
Move :with/:without check outside the method generated by validates_format_of
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/validations/format.rb12
1 files changed, 6 insertions, 6 deletions
diff --git a/activemodel/lib/active_model/validations/format.rb b/activemodel/lib/active_model/validations/format.rb
index 3b3dd4b827..c670dafc7c 100644
--- a/activemodel/lib/active_model/validations/format.rb
+++ b/activemodel/lib/active_model/validations/format.rb
@@ -47,13 +47,13 @@ module ActiveModel
raise ArgumentError, "A regular expression must be supplied as the :without option of the configuration hash"
end
- validates_each(attr_names, configuration) do |record, attr_name, value|
- if configuration[:with] && value.to_s !~ configuration[:with]
- record.errors.add(attr_name, :invalid, :default => configuration[:message], :value => value)
+ if configuration[:with]
+ validates_each(attr_names, configuration) do |record, attr_name, value|
+ record.errors.add(attr_name, :invalid, :default => configuration[:message], :value => value) if value.to_s !~ configuration[:with]
end
-
- if configuration[:without] && value.to_s =~ configuration[:without]
- record.errors.add(attr_name, :invalid, :default => configuration[:message], :value => value)
+ elsif configuration[:without]
+ validates_each(attr_names, configuration) do |record, attr_name, value|
+ record.errors.add(attr_name, :invalid, :default => configuration[:message], :value => value) if value.to_s =~ configuration[:without]
end
end
end