Follow Along as I Stumble on the Path to Learning RoR

Posts tagged “validation

Validations for Dates

I searched many times trying to figure out how to validate date of birth in my user model.  Finally, I stumbled on the validates_timeliness gem and it worked great for validating if a user was old enough to join my site.

after installing the gem, i just added the line from the example in my user model:

validates_date :date_of_birth, :before => lambda { 18.years.ago },
                              :before_message => "must be at least 18 years old"

https://github.com/adzap/validates_timeliness

Thank you for making this gem available adzap!

Advertisements