Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date depending of other date (re-open of #38) #39

Closed
sewid opened this issue Feb 21, 2011 · 2 comments
Closed

Date depending of other date (re-open of #38) #39

sewid opened this issue Feb 21, 2011 · 2 comments

Comments

@sewid
Copy link

sewid commented Feb 21, 2011

As posted as comment for closed issue #38, this code is not working:

My whole validation looks like:
validates_date :end_date,
:on_or_after => :start_date,
:on_or_before => lambda { |r| r.start_date + 90.days },
:unless => "start_date.blank?"

But dates that are more than 90 days in the future are accepted.

@adzap
Copy link
Owner

adzap commented Feb 21, 2011

The validation will only work if the start_date has a value.

Also, remove and the :unless and use :allow_blank => true.

If you can't get it working I need you provide a test case with example input data.

@sewid
Copy link
Author

sewid commented Feb 23, 2011

Got it working, it was a stupid one:

validates_date :end_date, 
  :on_or_after => :start_date, 
  :on_or_before => lambda { |c| c.start_date.to_date + 90.days }, 
  :allow_blank => true

Problem was, that my model has no database attached, so the start date field has no type. I had to convert it to a date and it works...

Thanks a lot!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants