Validating numericality of an attribute

suggest change

This validation restricts the insertion of only numeric values.

class Player < ApplicationRecord
  validates :points, numericality: true
  validates :games_played, numericality: { only_integer: true }
end

Besides :only_integer, this helper also accepts the following options to add constraints to acceptable values:

By default, numericality doesn’t allow nil values. You can use allow_nil: true option to permit it.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


ActiveRecord validations:
*Validating numericality of an attribute

Table Of Contents
11ActiveRecord validations
55CSV