Created
February 27, 2015 14:03
-
-
Save jcieslar/efc9ee9c9301818f7c37 to your computer and use it in GitHub Desktop.
Simple form input 'as: integer' brake rails numericality validations
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
/* wrong */ | |
= f.input :twitter_followers, as: :integer | |
/* correct */ | |
= f.input :twitter_followers |
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
validates :twitter_followers, numericality: true, if: -> { self.twitter_followers.present? } | |
# input value: twitter_followers = "Foo" | |
# wrong option | |
# return: self.twitter_followers => "" | |
# correct option | |
# return: self.twitter_followers => "Foo" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment