Forum: Ruby on Rails Validates that one date is before another one

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
(Guest)
on 2007-05-29 11:42
(Received via mailing list)
How could I use validation in Ror to validate that one date is before
the other date ?

Thanks.
Ben J. (Guest)
on 2007-05-29 12:05
removed_email_address@domain.invalid wrote:
> How could I use validation in Ror to validate that one date is before
> the other date ?
>
> Thanks.

In your model do:

def validate
errors.add(:some_attribute, "some message") if date_one > date_two
end

Depending on the logic you need to do nil checks as well. I am pretty
sure you can't compare a nil object with a date object.
(Guest)
on 2007-05-29 12:09
(Received via mailing list)
Thanks for the answer.

On 29 mai, 10:05, Ben J. <removed_email_address@domain.invalid>
MichaelLatta (Guest)
on 2007-05-29 18:38
(Received via mailing list)
You can put custom validations in the "validate" method on your
model.  You can use any ruby code there to do validations.

Look on the web or the source of existing validations for examples on
how to format the error objects.

Michael
David Gutierrez C. (Guest)
on 2007-05-29 18:49
(Received via mailing list)
Hi, im trying to unsubscribe me to the list, for one reason (i think the
server is catching for some spam rule) i cant unsubscribe me from the
website.

thnx for the help.



-----------------------
David Gutiérrez C.
Danilo Black : WebMedia
removed_email_address@domain.invalid
MSN: removed_email_address@domain.invalid
tel. +52 (81) 81 73 70 53
Blvd. Antonio L. Rdz. 2100, Col. Santa María
Monterrey, N.L. México, 64650






From: MichaelLatta <removed_email_address@domain.invalid>
Reply-To: <removed_email_address@domain.invalid>
Date: Tue, 29 May 2007 07:36:11 -0700
To: "Ruby on Rails: Talk" <removed_email_address@domain.invalid>
Subject: [Rails] Re: Validates that one date is before another one


You can put custom validations in the "validate" method on your
model.  You can use any ruby code there to do validations.

Look on the web or the source of existing validations for examples on
how to format the error objects.

Michael
This topic is locked and can not be replied to.