Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH] time_select ..., :include_blank => true

#2457

I'm running into issues with time_select raising MultiparameterAssignmentErrors. It's very similar to the email quoted below (http://markmail.org/message/lkzm...)

Hello everyone,

I'm having issues with a "time" field in a model. On the view, I use a time_select helper to generate the select for this field, and since I need this field to be NULL sometimes, I include the option :include_blank => true, like this:

<%= time_select 'support', 'duration', :minute_step => 15, :include_blank => true %>

The problem is that when I use :include_blank, the generated select comes with the hidden fields (of year, month and day) empty, like this:

00 01 02 03 21 22 23 : 00 15 30 45

And so, when I submit the form with the time field filled, I get an ActiveRecord::MultiparameterAssignmentErrors. If I don't set the option :include_blank => true, the hidden fields for year, month and day come filled with the respective current values, which are ignored by MySQL since we're storing them in a time field, not a datetime, and the insert or update goes on fine.

Is this a Rails bug (i'm using version 1.2.2) or am I doing something wrong here?

Thanks, Rodrigo.

Reported by Nolan Eakins · April 8th, 2009 @ 05:08 PM

State: duplicate
Milestone: 3.x
Assigned to: nobody
Importance: none

Activity

  1. Nolan Eakins
    Nolan Eakins
    • Title changed from time_select ..., :include_blank => true to [PATCH] time_select ..., :include_blank => true

    Here's a patch that adds a couple test cases and a fix for this problem. It's also available at http://github.com/sneakin/rails

    April 8th, 2009 @ 06:55 PM

  2. Nolan Eakins
    Nolan Eakins

    Here's a better approach than the above. It changes ActiveRecord::Base to add the date when it does a multiparameter assignment with only the hour and minute. The above is flawed when you select a blank hour and blank minute. The [Date]Time would still be created causing 0:00 to get selected.

    April 8th, 2009 @ 07:45 PM

  3. Daniel Tsadok
    Daniel Tsadok

    I'm having the same problem with time_select, :prompt => true

    July 13th, 2009 @ 09:03 PM

  4. Daniel Tsadok
  5. Daniel Tsadok
    Daniel Tsadok

    So I'm using the twelve-hour-plugin so that's probably what's doing it.

    July 13th, 2009 @ 10:04 PM

  6. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  7. Aditya Sanghi
    Aditya Sanghi
    • State changed from new to duplicate
    • Importance changed from to

    Please see ticket 4346 where we're still discussing this issue after 2 years. We've provided a patch with many more tests and comprehensively covers date/time/datetime issues as well as positional parameters among other issues.

    Marking this as duplicate. Please provide your comments and review on #4346 time_select not interpreting the multi-parameter correctly.

    October 17th, 2010 @ 07:40 PM