From 5ab94b2595836fe2de36fd632ba9577c459b1292 Mon Sep 17 00:00:00 2001 From: jzw Date: Wed, 5 Aug 2009 20:17:59 -0500 Subject: validates_length_of with maximum should allow nil [#2309 status:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activemodel/lib/active_model/validations/length.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'activemodel/lib/active_model/validations') diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb index db0439d447..81c97238d2 100644 --- a/activemodel/lib/active_model/validations/length.rb +++ b/activemodel/lib/active_model/validations/length.rb @@ -80,8 +80,10 @@ 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) + 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 end end end -- cgit v1.2.3