Created
March 7, 2011 17:15
-
-
Save jeffkreeftmeijer/858816 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I have two models: `AllowBlank` and `AllowNil`: | |
class AllowBlank < ActiveRecord::Base | |
validates :name, :presence => true, :allow_blank => true | |
end | |
class AllowNil < ActiveRecord::Base | |
validates :name, :presence => true, :allow_nil => true | |
end | |
# The `AllowBlank` validations should always pass and the `AllowNil` validations | |
# should pass on `nil` values, but fail on empty strings (`''`). | |
# Let's try it: | |
irb(main):001:0> AllowBlank.new.valid? | |
=> false | |
irb(main):002:0> AllowBlank.new(:name => '').valid? | |
=> false | |
irb(main):003:0> AllowNil.new.valid? | |
=> false | |
irb(main):004:0> AllowNil.new(:name => '').valid? | |
=> false | |
# Sad panda. :( | |
# So, using `allow_blank` should probably not be supported at all, but `allow_nil` should fail on empty strings. Right? ;) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment