# Getting a field value in a form with ruby

**URL:** <https://www.ruby-forum.com/t/getting-a-field-value-in-a-form-with-ruby/130851>\
**Category:** Ruby\
**Created:** [March 3, 2008, 10:49pm UTC](https://www.ruby-forum.com/t/getting-a-field-value-in-a-form-with-ruby/130851 "2008-03-03T22:49:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pimeamark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9e8a1a/32.png) [@pimeamark](https://www.ruby-forum.com/u/pimeamark)\
**Post date:** [March 3, 2008, 10:49pm UTC](https://www.ruby-forum.com/t/getting-a-field-value-in-a-form-with-ruby/130851/1 "2008-03-03T22:49:16Z")

</div>

Hi guys. I have a form to submit an assessment for one of my web apps.  
The model contains a datetime field called ends\_at which is when the  
assessment is supposed to end. Before, I had a datetime\_select field for  
this, but I put in a calendar popup to do the date for them. However, I  
also need them to choose the time as well so this is initially what i  
came up with

\<%= date\_field ‘assessment’, ‘ends\_at’, :value =\> “Click here…” %\>  
\<%= time\_select ‘assessment’, ‘ends\_at’%\>

But unfortunately this replaces the date they selected with today’s date  
because it discards the first date field after it reads the time one.  
Basically i want to know if there’s a way to somehow combine the date  
and the time fields in the form and perhaps pass them in a hidden field  
to the controller. I don’t know how to interact with the values inside  
fields before they’re submitted. Or if anyone has another suggestion on  
how to make that work I’d take that too 🙂 thanks alot!

---

<div class="post-metadata">

**Author:** ![pimeamark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9e8a1a/32.png) [@pimeamark](https://www.ruby-forum.com/u/pimeamark)\
**Post date:** [March 3, 2008, 10:57pm UTC](https://www.ruby-forum.com/t/getting-a-field-value-in-a-form-with-ruby/130851/2 "2008-03-03T22:57:13Z")

</div>

On Mon, Mar 3, 2008 at 4:49 PM, Mark Mr [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Or if anyone has another suggestion

I do… ask the Rails mailing list:  
[http://groups.google.com/group/rubyonrails-talk](http://groups.google.com/group/rubyonrails-talk). This is the Ruby  
Language ML.

On your actual problem - why do both fields have to have the same  
name? Can’t one be ends\_at\_date and the other be ends\_at\_time? And  
if they really must have the same name, try adding empty brackets  
after the method name: date\_field ‘assessment’, ‘ends\_at[]’. Then  
both values will come back in an array.

---

<div class="post-metadata">

**Author:** ![pimeamark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9e8a1a/32.png) [@pimeamark](https://www.ruby-forum.com/u/pimeamark)\
**Post date:** [March 3, 2008, 11:39pm UTC](https://www.ruby-forum.com/t/getting-a-field-value-in-a-form-with-ruby/130851/3 "2008-03-03T23:39:54Z")

</div>

Ok I’ll try that google group then. The fields are the same name because  
that’s the name of my field in the assessments database. I could split  
it up into 2 fields in my database but I was just wondering if there’s a  
way to just combine the 2 values so I can put them in that ends\_at  
field. Thanks though.

---

<div class="post-metadata">

**Author:** ![pimeamark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9e8a1a/32.png) [@pimeamark](https://www.ruby-forum.com/u/pimeamark)\
**Post date:** [March 3, 2008, 11:04pm UTC](https://www.ruby-forum.com/t/getting-a-field-value-in-a-form-with-ruby/130851/4 "2008-03-03T23:04:53Z")

</div>

Hi,

I agree that you should take this to the Rails mailing list.

Here’s another idea to play with, though.

Give each field a distinct name, e.g., assessment\_end\_date and  
assessment\_end\_time. When the form is submitted, combine them. Here’s a  
rudimentary way it could be done:

assessment.end\_at = DateTime.parse("#{params[assessment\_end\_date]}  
#{params[assessment\_end\_time]}")

Good luck,  
Craig

---

<div class="post-metadata">

**Author:** ![pimeamark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9e8a1a/32.png) [@pimeamark](https://www.ruby-forum.com/u/pimeamark)\
**Post date:** [March 3, 2008, 11:51pm UTC](https://www.ruby-forum.com/t/getting-a-field-value-in-a-form-with-ruby/130851/5 "2008-03-03T23:51:24Z")

</div>

On Mon, Mar 3, 2008 at 5:39 PM, Mark Mr [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Ok I’ll try that google group then. The fields are the same name because  
> that’s the name of my field in the assessments database. I could split  
> it up into 2 fields in my database but I was just wondering if there’s a  
> way to just combine the 2 values so I can put them in that ends\_at  
> field. Thanks though.

I suggest you dig into the documentation for the composed\_of flag to  
ActiveRecord associations. It might give you just the solution you’re  
looking for.
