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