Rails 2.3.5: How to handle this type of validation

Posted by randombits on Stack Overflow See other posts from Stack Overflow or by randombits
Published on 2010-05-08T16:12:10Z Indexed on 2010/05/08 16:18 UTC
Read the original article Hit count: 142

Filed under:
|

The use case is simple.

I allow users to enter in an expiration field which needs to be between 1 and 15 into a form. The model takes that number and converts it into a datetime (such as adding 15 days from today) and stores it in the database.

What's the correct way to actually validate that though? Do I validate against the datetime format that gets persisted in the database or the select box (1..15) that the user gets to pick through the form? I want to be able to validate that the user is putting in 1..15.. How is this done with ActiveRecord validation in Rails 2.3.5?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about activerecord