Convert input to integer before save in rails

Posted by Micke on Stack Overflow See other posts from Stack Overflow or by Micke
Published on 2010-04-21T17:40:54Z Indexed on 2010/04/21 17:43 UTC
Read the original article Hit count: 502

Hello, i have a set of select inputs representing a users birthday: birthyear, birthmonth and birthday. And i want to validate birthyear like this:

  validates_inclusion_of :birthyear, :in => Date.today.year-50..Date.today.year-12

So the user can be at least 12 years but at most 50 years when they are registering. But my problem is that the variable from the input is a string and not an integer.

So how can i convert the input to an integer? or is there any easier way to check the users age?

Thanks, Micke

© Stack Overflow or respective owner

Related posts about ruby

Related posts about ruby-on-rails