# Custom validations - where's the original value

**URL:** <https://www.ruby-forum.com/t/custom-validations-wheres-the-original-value/165216>\
**Category:** Rails\
**Created:** [April 10, 2009, 9:32am UTC](https://www.ruby-forum.com/t/custom-validations-wheres-the-original-value/165216 "2009-04-10T09:32:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [April 10, 2009, 9:32am UTC](https://www.ruby-forum.com/t/custom-validations-wheres-the-original-value/165216/1 "2009-04-10T09:32:38Z")

</div>

Playing with custom validations (i need to start doing this)

This works…

def validate

```
 errors.add :date_of_birth, 'is not a valid date' if

```

Chronic.parse(date\_of\_birth.to\_s).nil?

end

Trouble is when the form is re-rendered it’s lost the users original  
selection - how do i fix it up?

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [April 10, 2009, 10:07am UTC](https://www.ruby-forum.com/t/custom-validations-wheres-the-original-value/165216/2 "2009-04-10T10:07:14Z")

</div>

thinking this through maybe this is the problem

 \<%= date\_select 'enquiry', 'date\_of\_birth', :order =\> [:day, :month, :year], :start\_year =\> 1950, :end\_year =\> 2000, :include\_blank =\> true %\>

is the include blank the problem (maybe it’s getting blanked on the  
re-render)?

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [April 10, 2009, 10:31am UTC](https://www.ruby-forum.com/t/custom-validations-wheres-the-original-value/165216/3 "2009-04-10T10:31:17Z")

</div>

bingo bob wrote:

> thinking this through maybe this is the problem
> 
> \<%= date\_select 'enquiry', 'date\_of\_birth', :order =\> [:day, :month, :year], :start\_year =\> 1950, :end\_year =\> 2000, :include\_blank =\> true %\>
> 
> is the include blank the problem (maybe it’s getting blanked on the  
> re-render)?
> 
> this looks like the problem to me - but how do i fix it?
> 
> I’d like to show a blank on the initial form but not when a validation  
> fails and the form is shown again (the user should see the original  
> selection?

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [April 10, 2009, 11:15pm UTC](https://www.ruby-forum.com/t/custom-validations-wheres-the-original-value/165216/4 "2009-04-10T23:15:06Z")

</div>

No, the include\_blank is not the problem I think.  
date\_select automatically selects the value given in  
@enquiry.date\_of\_birth…

The problem must be somewhere else. Are you sure  
@enquiry is not reset? A mistake I used to make is to  
redirect from the create to the new action instead  
of directly rendering the new template from the create action  
when rerendering the form.

anyway, this is just a guess…  
I need to see how exactly you are rendering the form.

On Apr 10, 11:31 am, bingo bob [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
