Axinte Logo
2009-Aug-27 20:42 UTC
Date precedence validation (ex. Round Trip travel dates)
Hello, I''m trying to validate 2 dates that were provided by the user using a form that wraps a model. I want to do the following 2 validations in the model: **** validate the date format => That I know how to do! **** if the format validation was a success, then ensure that date1 is smaller or equal than date2 => That''s I do not know I''ve spend, in vain, more than 2 hours to find a solution in order to understand: ** 1 ** How to trigger a second validation only if the first one was an success? ** 2 ** How to compare to dates using the macros in ActiveRecord? Any ideas? Kind regards Axinte --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Patrick Doyle
2009-Aug-27 20:50 UTC
Re: Date precedence validation (ex. Round Trip travel dates)
Why not convert each date to Ruby Time objects and compare those? --wpd
Colin Law
2009-Aug-27 21:21 UTC
Re: Date precedence validation (ex. Round Trip travel dates)
2009/8/27 Axinte Logo <alogo-2zXVbNbNaFTHNWWW6QW1Ag@public.gmane.org>:> Hello, > I''m trying to validate 2 dates that were provided by the user using a form > that wraps a model. > I want to do the following 2 validations in the model: > **** validate the date format => That I know how to do! > **** if the format validation was a success, then ensure that date1 is > smaller or equal than date2 => That''s I do not know > I''ve spend, in vain, more than 2 hours to find a solution in order to > understand: > ** 1 ** How to trigger a second validation only if the first one was > an success?Not sure about this, you may have to provide your own validate method in the model rather than use the built in ones (or as well as)> ** 2 ** How to compare to dates using the macros in ActiveRecord?Assuming they are ruby Dates or Times or DateTimes just compare them using <= or whatever. Colin