Validates that one date is before another one

How could I use validation in Ror to validate that one date is before
the other date ?

Thanks.

[email protected] 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.

Thanks for the answer.

On 29 mai, 10:05, Ben J. [email protected]

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

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
[email protected]
MSN: [email protected]
tel. +52 (81) 81 73 70 53
Blvd. Antonio L. Rdz. 2100, Col. Santa María
Monterrey, N.L. México, 64650

From: MichaelLatta [email protected]
Reply-To: [email protected]
Date: Tue, 29 May 2007 07:36:11 -0700
To: “Ruby on Rails: Talk” [email protected]
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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs