Railsで「整数のみ」、「0以上の正の数のみ」のvalidatesの書き方
569 ワード
環境
Rails 5.1.7
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
結論
validates :price, presence: true, numericality: {only_integer: true, greater_than_or_equal_to: 0}
解説
validates :price, presence: true, numericality: {only_integer: true, greater_than_or_equal_to: 0}
「整数のみ」の箇所
only_integer: true,
「0以上の正の数のみ」の箇所
greater_than_or_equal_to: 0
Author And Source
この問題について(Railsで「整数のみ」、「0以上の正の数のみ」のvalidatesの書き方), 我々は、より多くの情報をここで見つけました https://qiita.com/syohhe/items/ecef500da2cd7956489d著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .