# Date Validation problem

**URL:** <https://discuss.rubyonrails.org/t/date-validation-problem/18783>\
**Category:** rubyonrails-talk\
**Created:** [October 2, 2007, 1:21pm UTC](https://discuss.rubyonrails.org/t/date-validation-problem/18783 "2007-10-02T13:21:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![GPB](https://avatars.discourse-cdn.com/v4/letter/g/49beb7/32.png) [@GPB](https://discuss.rubyonrails.org/u/GPB)\
**Post date:** [October 2, 2007, 1:21pm UTC](https://discuss.rubyonrails.org/t/date-validation-problem/18783/1 "2007-10-02T13:21:46Z")

</div>

Hello,

I have this validation code in my model.

def validate errors.add(:last\_action\_date, "some message") if next\_action\_date \< last\_action\_date end

Two date select fields.

Without the code, as long as dates are valid (no 31st of February), no errors, works ok.

With the code in place, when the next\_action\_date is before the last\_action\_date then I get a NoMethodError

You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.inject

The validation seems to work, but instead of stopping the code and going back into edit mode like all other rails validations, instead it gives an error.

Can anyone point me in the right direction?

Thank you,

GPB

---

<div class="post-metadata">

**Author:** ![GPB](https://avatars.discourse-cdn.com/v4/letter/g/49beb7/32.png) [@GPB](https://discuss.rubyonrails.org/u/GPB)\
**Post date:** [October 2, 2007, 1:42pm UTC](https://discuss.rubyonrails.org/t/date-validation-problem/18783/2 "2007-10-02T13:42:02Z")

</div>

To complement my post...

This is the log when the dates pass the validation:

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [October 2, 2007, 1:59pm UTC](https://discuss.rubyonrails.org/t/date-validation-problem/18783/3 "2007-10-02T13:59:45Z")

</div>

You've left out the stack trace for the actual exception thrown.

Fred

---

<div class="post-metadata">

**Author:** ![GPB](https://avatars.discourse-cdn.com/v4/letter/g/49beb7/32.png) [@GPB](https://discuss.rubyonrails.org/u/GPB)\
**Post date:** [October 2, 2007, 2:36pm UTC](https://discuss.rubyonrails.org/t/date-validation-problem/18783/4 "2007-10-02T14:36:30Z")

</div>

Hi Fred,

I figured it out. Had to do with the placement of the find statements for creating the arrays in the controller.

They were at the bottom of the "update", when I put them at the top it solved the problem.

Thank you anyway for answering.

GPB
