Forum: Ruby on Rails dynamic validations

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A971282eda2c4050c35a8974ad5089e5?d=identicon&s=25 Tim Dunn (timdunn2)
on 2009-03-03 06:46
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
0348be81e22f24afdaa6e4f137aa9dfc?d=identicon&s=25 Priya Buvan (priyadharsini)
on 2009-03-03 07:04
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..
A971282eda2c4050c35a8974ad5089e5?d=identicon&s=25 Tim Dunn (timdunn2)
on 2009-03-05 03:41

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
This topic is locked and can not be replied to.