minimum maximum validation between two attributes


There have been many instances when working with rails application, I had to put the minimum, maximum custom validator or active record callbacks check if the maximum value is valid compared to minimum value.

Few such examples are:

1. Comparing minimum and maximum salary.
Maximum salary should not be less than the minimum salary. It can only be equal or greater than the minimum salary.
Minimum salary or Maximum salary can be blank because we might have constraint on minimum salary and no cap on maximum salary or vice a versa.

2. Comparing the age.
Comparing the father son age. Son’s age should not be more than father’s age

3. Comparing Minimum, maximum points to avail an offer.

Though writing a custom validator is a matter of 5 minutes. But for each of the case in different application you have to repeat the code in one of the module or…

View original post 152 more words


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s