LoginSignup
5
6

More than 3 years have passed since last update.

Railsで「整数のみ」、「0以上の正の数のみ」のvalidatesの書き方

Posted at

環境

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}

解説

「整数のみ」の箇所
only_integer: true,

「0以上の正の数のみ」の箇所
greater_than_or_equal_to: 0

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6