[ActiveModel::Validations] Add an option in for the numeric validation

Hi,

I searched any topics about the option ‘in’ for the numeric validations in the models but I found nothing. Thus, I suggest to add the ability to define the options of the validation with help of Range of Numeric values. The benefit will be the reduction of validation size in the models simplifying maintenance and reading of the code.

We could change this code:

class Person
  validates_numericality_of :age, greater_than_or_equal_to: 1, less_than_or_equal_to: 100
end

by:

class Person
  validates_numericality_of :age, in: 1..100
end

I’ve prepared an implementation for this feature. Thus, can I submit a pull request with this feature?

Best regards.

Does something like validates :age, :inclusion => { :in => 0..100 } do what you want?

Colin

Hi,

How do you combine it if you want only integer (only_integer: true), furthermore, I think my proposition is a shortcut of a combination of less_than, greater_than, … Thus, it concerns the numeric validation and not the inclusion validation?

Thanks.