Forum: Ruby on Rails How to validate expiry date

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.
Sainaba S. (Guest)
on 2006-01-17 13:49
Hi

     How can I do the validation of date expiry (if the date is less
than today) in ruby.Can I do it using the validate method or other def
in the model class?

                             Thanks in advance,
                             Sainaba.
Eszter B. (Guest)
on 2006-01-17 15:21
(Received via mailing list)
sainaba sainu wrote:
>      How can I do the validation of date expiry (if the date is less
> than today) in ruby.

You can do something like this:

  def validate
    if expiry_date < Date.today
      errors.add(:expiry_date , "should be a future date")
    end
  end


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