This project is archived and is in readonly mode.

#3681 ✓resolved
Michael Guterl

date_select with :discard_day => true doesn't allow for NULL dates

Reported by Michael Guterl | January 10th, 2010 @ 08:16 PM

I hope this looks okay, preview is busted.

Original ticket here: http://dev.rubyonrails.org/ticket/7979

Summary from original:

I'm using the following date_select in a view:

date_select('project', 'start_at',
  :end_year => 1980, :start_year =>Date.today.year,
  :discard_day => true,
  :include_blank => true,
  :order => [:month, :year])

However, when selecting the blank (:include_blank) option, the date is not typecast to NULL as it should be - rather, it is set to 2001 (for some reason).

A debug() of params[:project] reveals that the :discard_day option causes rails to set the start_at(3i) param to "1", which then causes the entire date to not be recognized as a nil submission.

Original comment:

This appears to happen when start_at was set already somewhere in the code. For instance by a default value or by assignment triggered on the previous request. Because start_at was already set, the helper will set the day value of start_at to 1 to make sure that whatever month or year is chosen, it will be a valid date. This is normally a good assumption, but not when you want to allow blank.

When these values eventually end up in ActiveRecord the automated type casting on multiparameter assign ends up calling Time.local(1) to set start_at. Which happens to be Mon Jan 01 00:00:00 +0100 2001. So it interprets the day value as a year value. This causes two problems; ActiveRecord can't do validation on the time anymore, but it also uses the parameter for the wrong argument.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages