diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-08-08 19:08:39 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-08-08 19:08:39 +0100 |
commit | c6fe49b00921cda55af2dc311dd432795c4313f5 (patch) | |
tree | 9969d333e131dd2a795a10522151580ef69ef7ad /activemodel/lib | |
parent | 5ab94b2595836fe2de36fd632ba9577c459b1292 (diff) | |
download | rails-c6fe49b00921cda55af2dc311dd432795c4313f5.tar.gz rails-c6fe49b00921cda55af2dc311dd432795c4313f5.tar.bz2 rails-c6fe49b00921cda55af2dc311dd432795c4313f5.zip |
Simplyfy validates_length_of and remove puts
Diffstat (limited to 'activemodel/lib')
-rw-r--r-- | activemodel/lib/active_model/validations/length.rb | 11 |
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 |