Understanding date_select naming conventions

I am using the date_select helper to generate date select elements in a
form.

I notice that the generated HTML shows that these selects have the
following names:

Month: current_job[StartDate(2i)]
Day: current_job[StartDate(3i)]
Year: current_job[StartDate(1i)]

I’m assuming that the Xi identifiers somehow specify the appropriate
date part from a date or time value.

Can anyone shed some light on how this works? Where can I get definite
info. on it?

Also, I am using select_hour, select_minute, and select_second to handle
the time portion of another field. Do I need to use a similar naming
convention so that the correct time components will be set upon form
submission?

Thanks,
Wes

Wes G. wrote:

I am using the date_select helper to generate date select elements in a
form.

I notice that the generated HTML shows that these selects have the
following names:

Month: current_job[StartDate(2i)]
Day: current_job[StartDate(3i)]
Year: current_job[StartDate(1i)]

I’m assuming that the Xi identifiers somehow specify the appropriate
date part from a date or time value.

I would love to see more about it as well. I’ve found that the attribute
will come back as “attribute(1i)” through “attribute(5i)” for
select_datetime.

I think the ActiveRecord automatically converts these into a Date or
Time object automatically, but I’m using a proxy object, so I have to
take the component parts and create a date from them.

I was expecting something like this_

time = Time.local({:year => params[:record][“attribute(1i)”], :month =>
params[:record][“attribute(2i)”], …})

but that is not shown in the documentation. All I have found is
Time.local() taking an array and parsing it topographicaly (e.g. first
item is year by position). And that does not seem to work when I pass
the proxy class’ attribute mutator an array as a parameter.

I’m Old School (Object Pascal and Java). I understand that one cannot
overload methods with duck typing, but it seems psychotic that I cannot
tell if the argument is an array, a hash, or a scalar value (like a
Time). I cannot beleave that one is supposed to use exception catching
to deal with different types.

Cheers

The number inside the parenthesis means the parameter position and the
the i
means to convert the value into an integer. The convention is used by
active
record to convert multipart fields into one value. For example:

current_job[StartDate(2i)]
current_job[StartDate(3i)]
current_job[StartDate(1i)]

Active record will convert the value of current_job[StartDate(1i)] into
an
integer (i) and use it as the first parameter for the mktime function
(1). It
will also convert the value of current_job[StartDate(2i)] into an
integer (i)
and use it as the second parameter for the mktime function (2). The same
is true
for current_job[StartDate(3i)]. You canfind some info in the API docs,
looking
for something like multi part field or values. I had to dig into
ActiveRecord’s
source to see the magic.

Hope this clears up your question,
juantar
http://tarpri.com

On 7/6/06, juantar [email protected] wrote:

will also convert the value of current_job[StartDate(2i)] into an integer (i)
and use it as the second parameter for the mktime function (2). The same is true
for current_job[StartDate(3i)]. You canfind some info in the API docs, looking
for something like multi part field or values. I had to dig into ActiveRecord’s
source to see the magic.

I can’t seem to get any magic to work with date_select on the receiving
end.

The parameters that arrive to my controller are

params=>{“commit”=>“Save”, “tick”=>{“climb_id”=>“1”,
“send_date(1i)”=>“2002”, “send_date(2i)”=>“8”, “send_date(3i)”=>“14”}}

In my controller that receives these params I have

tick = Tick.find_by_climb_id(params[:tick][:climb_id])
tick.update_attributes(:send_date=>params[:tick][:send_date])

but this results in null in the database because there isn’t a
params[:tick][:send_date]

Do I have to manually reassemble the date from the params? I’ve seen
that people do this but it seems like the (1i) etc should make it
happen automatically.

Is there a magic helper that validates the date as an actual real date?

Thanks,
Peter