aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activemodel/lib')
-rw-r--r--activemodel/lib/active_model/validations/length.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb
index db0439d447..3e76796355 100644
--- a/activemodel/lib/active_model/validations/length.rb
+++ b/activemodel/lib/active_model/validations/length.rb
@@ -80,9 +80,14 @@ module ActiveModel
validates_each(attrs, options) do |record, attr, value|
value = options[:tokenizer].call(value) if value.kind_of?(String)
- unless !value.nil? and value.size.method(validity_checks[option])[option_value]
- record.errors.add(attr, key, :default => custom_message, :count => option_value)
+
+ valid_value = if option == :maximum
+ value.nil? || value.size.send(validity_checks[option], option_value)
+ else
+ value && value.size.send(validity_checks[option], option_value)
end
+
+ record.errors.add(attr, key, :default => custom_message, :count => option_value) unless valid_value
end
end
end