codegram / date_validator

A simple, ORM agnostic, Ruby >=2.2 compatible date validator for Rails, based on ActiveModel.
http://thoughts.codegram.com/date-validation-with-rails-3
MIT License
496 stars 82 forks source link

time range #32

Closed mattherick closed 12 years ago

mattherick commented 12 years ago

is it possible to do something like that: validates :end_at, :date => { :after => :start_at, :before => Proc.new { :start_at + 9.days } }

Thanks in advance for a short answer.

txus commented 12 years ago

It should be:

validates :end_at, :date => { :after => :start_at, :before => Proc.new { |record| record.start_at + 9.days } }

Because when given a proc, it yields the record, so you can call methods on it (or provide a block with no arguments as well).