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


> 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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to