Validates that one date is before another one


#1

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

Thanks.


#2

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.


#3

Thanks for the answer.

On 29 mai, 10:05, Ben J. removed_email_address@domain.invalid


#4

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


#5

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