# Understanding date\_select naming conventions

**URL:** <https://www.ruby-forum.com/t/understanding-date-select-naming-conventions/97384>\
**Category:** Rails\
**Created:** [July 6, 2006, 7:25pm UTC](https://www.ruby-forum.com/t/understanding-date-select-naming-conventions/97384 "2006-07-06T19:25:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [July 6, 2006, 7:25pm UTC](https://www.ruby-forum.com/t/understanding-date-select-naming-conventions/97384/1 "2006-07-06T19:25:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [July 6, 2006, 7:59pm UTC](https://www.ruby-forum.com/t/understanding-date-select-naming-conventions/97384/2 "2006-07-06T19:59:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [July 7, 2006, 4:15am UTC](https://www.ruby-forum.com/t/understanding-date-select-naming-conventions/97384/3 "2006-07-07T04:15:46Z")

</div>

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](http://tarpri.com)

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [August 15, 2006, 2:20pm UTC](https://www.ruby-forum.com/t/understanding-date-select-naming-conventions/97384/4 "2006-08-15T14:20:30Z")

</div>

On 7/6/06, juantar [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
