# Datetime\_select and Active Record

**URL:** <https://www.ruby-forum.com/t/datetime-select-and-active-record/122932>\
**Category:** Rails\
**Created:** [December 12, 2007, 9:39pm UTC](https://www.ruby-forum.com/t/datetime-select-and-active-record/122932 "2007-12-12T21:39:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pete](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ab097/32.png) [@pete](https://www.ruby-forum.com/u/pete)\
**Post date:** [December 12, 2007, 9:39pm UTC](https://www.ruby-forum.com/t/datetime-select-and-active-record/122932/1 "2007-12-12T21:39:09Z")

</div>

If I have a form similar to the one below, and ‘start’ is a “string”  
field in my Database. Is there a way to take all of the date/time  
params and put them into ‘start’ without too much hacking? I would  
like this to be as clean as possible.

Start Time  
\<%= form.datetime\_select 'start' %\>

To clarify, when “new” is called, my rails app does the standard:  
@period = Period.new(params[:whatever])

I’d rather not break that apart if possible. Please let me know if  
this doesn’t make  
sense.

Thanks!

---

<div class="post-metadata">

**Author:** ![pete](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ab097/32.png) [@pete](https://www.ruby-forum.com/u/pete)\
**Post date:** [December 12, 2007, 10:14pm UTC](https://www.ruby-forum.com/t/datetime-select-and-active-record/122932/2 "2007-12-12T22:14:33Z")

</div>

I don’t know if I understand you correctly, but it sounds like you are  
concerned that the datetime select is split into multiple selection  
lists and you want the date stored as one attribute in the database.

If this is the case, rails should automatically ‘fuse’ all the  
parameters into one datetime value as long as your column is set to  
datetime and not string.

---

<div class="post-metadata">

**Author:** ![pete](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ab097/32.png) [@pete](https://www.ruby-forum.com/u/pete)\
**Post date:** [December 12, 2007, 10:21pm UTC](https://www.ruby-forum.com/t/datetime-select-and-active-record/122932/3 "2007-12-12T22:21:36Z")

</div>

You got it exactly, however I modified the column attribute to  
datetime and simply passing it back, I get an error:

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.inject

---

<div class="post-metadata">

**Author:** ![pete](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ab097/32.png) [@pete](https://www.ruby-forum.com/u/pete)\
**Post date:** [December 12, 2007, 10:23pm UTC](https://www.ruby-forum.com/t/datetime-select-and-active-record/122932/4 "2007-12-12T22:23:27Z")

</div>

Nevermind, that worked perfectly. Thank you!
