Forum: Ruby on Rails custom validations - where's the original value..

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.
bingo b. (Guest)
on 2009-04-10 11:32
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?
bingo b. (Guest)
on 2009-04-10 12:07
thinking this through maybe this is the problem


<td> <%= 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)?
bingo b. (Guest)
on 2009-04-10 12:31
bingo bob wrote:
>
> thinking this through maybe this is the problem
>
>
> <td> <%= 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?
nico (Guest)
on 2009-04-11 01:15
(Received via mailing list)
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>
This topic is locked and can not be replied to.