aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model
diff options
context:
space:
mode:
authorColin Kelley <colindkelley@gmail.com>2012-12-26 10:31:05 -0800
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-12-26 18:19:27 -0300
commitd4c30a0226386f291bd8b1959fed12b3aca19164 (patch)
tree13633203d5f52c62dad47761708eed251508bfa7 /activemodel/lib/active_model
parentd9ce4fa7ac21dd3f623defa3cb1ac1a87b670ebe (diff)
downloadrails-d4c30a0226386f291bd8b1959fed12b3aca19164.tar.gz
rails-d4c30a0226386f291bd8b1959fed12b3aca19164.tar.bz2
rails-d4c30a0226386f291bd8b1959fed12b3aca19164.zip
Tests and fix for validates_presence of :allow_nil, :allow_blank
Conflicts: activemodel/lib/active_model/errors.rb
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r--activemodel/lib/active_model/errors.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index 963e52bff3..92c2512aa4 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -322,9 +322,15 @@ module ActiveModel
# person.errors.messages
# # => {:name=>["can't be blank"]}
def add_on_blank(attributes, options = {})
+ return if options[:allow_blank]
+
Array(attributes).each do |attribute|
value = @base.send(:read_attribute_for_validation, attribute)
- add(attribute, :blank, options) if value.blank?
+ if value.nil?
+ add(attribute, :blank, options) unless options[:allow_nil]
+ elsif value.blank?
+ add(attribute, :blank, options)
+ end
end
end