On Mon, Jun 8, 2009 at 10:59 PM, Erwin
<yves_dufour-ee4meeAH724@public.gmane.org> 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
> 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:in `parse''
> from (irb):2
> >>
>
> how can I write my validation Proc ?
>
> thanks for your help
>
> erwin
> >
>
- Sandip R~
--
Ruby on Rails Developer
http://sandip.sosblog.com
http://funonrails.wordpress.com
www.joshsoftware.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---