Date validation how to chech ArgumentError

I wrote in my user model :

def validate
errors.add(:born_on, “is invalid”) if Proc.new { |user|
DateTime.parse(user.born_on) }
end

it’s wrong I know, running in the console raises an ArgumentError

Loading development environment (Rails 2.3.2)

born_on = “99/99/9999”
=> “99/99/9999”

DateTime.parse(born_on)
ArgumentError: invalid date
from /usr/local/lib/ruby/1.8/date.rb:1573:in new_by_frags' from /usr/local/lib/ruby/1.8/date.rb:1618:inparse’
from (irb):2

how can I write my validation Proc ?

thanks for your help

erwin

On Mon, Jun 8, 2009 at 10:59 PM, Erwin [email protected] wrote:

I wrote in my user model :

def validate
errors.add(:born_on, “is invalid”) if Proc.new { |user|
DateTime.parse(user.born_on) }
end

Try out this

def validate
DateTime.parse(self.born_on)
rescue
errors.add(:born_on, “is invalid”)
end

how can I write my validation Proc ?

thanks for your help

erwin

thanks… I was looking on one direction only… better 2
eyes ;-))