time_select and MultiparameterAssignmentErrors

Hello,

I have a couple of time field (MySQL data type: time) "start_time" and
"end_time", and I'm trying to use a time_select helper to save the
data. Here's how I'm using it:

<%= form.time_select :activity_start_time, :prompt =>
true, :ignore_date => true %>
<%= form.time_select :activity_end_time, :prompt => true, :ignore_date
=> true %>

and I get this error:

2 error(s) on assignment of multiparameter attributes

when it hits the controller at this line:

    @activity = Activity.new(params[:activity])

Here's the parameters:

{"authenticity_token"=>"5MmHPVW9VupApm3Qk17OEaf4M5dTk7iw9HhFbhOM3Q0=",
"activity"=>{"name"=>"",
"notes"=>"",
"activity_start_time(4i)"=>"10",
"activity_end_time(4i)"=>"13",
"activity_start_time(5i)"=>"00",
"activity_end_time(5i)"=>"00",
"activity_date"=>"04/03/2010",
"hours"=>"",
"description"=>"",
"activity_type"=>"40"}}

What am I doing wrong?

Update - I just noticed that it will save a new record without this
error if I have the minutes other than "00". But there still is an
issue, since it saves the parameters as Year and Month instead of Hour
and Minute! So this is interpreted as

"activity_start_time(4i)"=>"10",
"activity_end_time(4i)"=>"13",
"activity_start_time(5i)"=>"05",
"activity_end_time(5i)"=>"05",

activity_start_time = 2010-05-01 00:00:00
activity_end_time = 2013-05-01 00:00:00

Has anyone encountered this problem?

Well, I found out that I can't have ANY extra constraints on it. That
seems to make time_select parameters interpreted incorrectly.

Can't have:
:prompt => true
:include_blank => true
:ignore_date => true

So my form field is reduced to:

<%= form.time_select :activity_start_time %>
<%= form.time_select :activity_end_time %>

and
    @activity.activity_start_time = Time.parse("00:00")
    @activity.activity_end_time = Time.parse("00:00")

inside the controller, so that the current time won't be selected by
default for new records. Kind of annoying that I can't have prompt or
blank at the top. :-\ If anyone has figured out a way to make
time_select work as expected, I'm all ears!

So I just scaffolded, tested and successfully reproduced your problem
exactly. Playing around in the console gave some interesting results:

Activity.new 'activity_start_time(1i)' => '2010', 'activity_start_time(22i)' => '11', 'activity_start_time(100i)' => '7'
... activity_start_time: "2010-07-11 00:00:00"

So for multiparameter attribute assignment, it just sorts the index
number alphabetically and uses the data fields to assign to the
object, in order (at least for Time / DateTime objects and likely for
Date objects as well). It then appears to begin assigning the data to
the fields, starting with the "first" field (year) and moving on,
ignoring the actual numeric value of the "index" (such as my 100 above
which results in its value becoming the month). So, with the rails
helper defaults of '4i' and '5i', the 5 becomes the 'month' and '00'
is an invalid month number.

So, this would appear to be a weakness/bug in rails from my
perspective. I'd think it should actually strip off the data-type
character (the 'i' chars in this case) and cast the remaining 'index'
characters to a Fixnum (again, at least for date/time types, not sure
about aggregates/others) at which point it should respect the number
as an offset: 1 => year, 2 => month, and so on so that this usage, as
written out by the view helper, actually works as expected.

Anyhow, just my two cents.

To work around, I'd drop the :ignore_date options in your helpers.
Then manually overwrite the YYYY-MM-DD value(s) of these two fields to
a consistent default (since I'm assuming you're not using the date
part anyway) so you can compare time values.

Then you should file a bug report :slight_smile:

Thanks for confirming what I was experiencing! (At least I know I'm
not seeing things...)
I've never submitted a bug report for ror - is this the right place?
https://rails.lighthouseapp.com/dashboard

I've never submitted a bug report for ror - is this the right place?https://rails.lighthouseapp.com/dashboard

I've never submitted a bug report either. Looks like the right place
to me.

Kendall,

This link will take you to an page with some information on how to create a bug report as well.

https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview

Anthony Crumley

http://commonthread.com

I created a profile there and submitted a ticket - thanks for your
help!