Dynamic validations


#1

I am wondering what code I should put inside the class of my model to do
validations for all columns of a given data type. For example I want to
validate whether it is a number or not if it is of type integer. I want
to do this so I don’t have to do individual validations on every column


#2

Tim Dunn wrote:

I am wondering what code I should put inside the class of my model to do
validations for all columns of a given data type. For example I want to
validate whether it is a number or not if it is of type integer. I want
to do this so I don’t have to do individual validations on every column

Use validates_numericality_of :columnname

Tell your problem clearly so that we can try for solution…


#3

say i have five columns of type integer like: age, book_number,
page_number, number_of_pages, number_of_people
and instead of doing this
validate_numericality_of :age, :book_number, :page_number,
:number_of_pages, :number_of_people

I want to name all columns that are of type integer to an array and for
every element of that array validate if its a number or not