In Rails 4, how can you add a model validation for a maximum value on an integer column?
For example, I want to add a validation to the column "age", to have a maximum value of 100.
There are many questions with answers for Rails 3 and earlier. The docs do not mention any way of checking integer values.
Take a look at the numericality validators.
In your case, something like
validates :age, numericality: { less_than_or_equal_to: 100, only_integer: true }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With