# Multiple text\_field for one variable

**URL:** <https://www.ruby-forum.com/t/multiple-text-field-for-one-variable/68556>\
**Category:** Rails\
**Created:** [September 13, 2006, 4:19pm UTC](https://www.ruby-forum.com/t/multiple-text-field-for-one-variable/68556 "2006-09-13T16:19:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sw0rdfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@sw0rdfish](https://www.ruby-forum.com/u/sw0rdfish)\
**Post date:** [September 13, 2006, 4:19pm UTC](https://www.ruby-forum.com/t/multiple-text-field-for-one-variable/68556/1 "2006-09-13T16:19:28Z")

</div>

Ok this is probably a silly question, but I’ve been up all night, and  
I’m not thinking right 🙂

Is there a way to have a model’s variable set using multiople  
text\_fields, while still using the

\<%= text\_field :order, :time %\> but have two text\_fields for it, and  
then

order.create(params[:order]) in the controller…

I know the date\_select helper, creates parameters called date(1i),  
date(2i), date(3i)… I guess I’m wondering if I can manually do the  
same thing, for lets say “time” have a drop down for the hour, and  
drop down for the minutes w/o having to then write manual code to set  
the time…

I hope that makes sense.

---

<div class="post-metadata">

**Author:** ![sw0rdfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@sw0rdfish](https://www.ruby-forum.com/u/sw0rdfish)\
**Post date:** [September 13, 2006, 10:54pm UTC](https://www.ruby-forum.com/t/multiple-text-field-for-one-variable/68556/2 "2006-09-13T22:54:29Z")

</div>

Help!!! Please!!! ☹

---

<div class="post-metadata">

**Author:** ![sw0rdfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@sw0rdfish](https://www.ruby-forum.com/u/sw0rdfish)\
**Post date:** [September 13, 2006, 11:22pm UTC](https://www.ruby-forum.com/t/multiple-text-field-for-one-variable/68556/3 "2006-09-13T23:22:33Z")

</div>

On Wednesday 13 September 2006 16:14, sw0rdfish wrote:

> I know the date\_select helper, creates parameters called date(1i),  
> date(2i), date(3i)… I guess I’m wondering if I can manually do the  
> same thing, for lets say “time” have a drop down for the hour, and  
> drop down for the minutes w/o having to then write manual code to set  
> the time…

Yes, you can. If you need to know the details, have a look at the source  
code of ActiveRecord::Base#assign\_multiparameter\_attributes and  
following.

Basically, if you have an aggregation defined where the constructor of  
the aggregate class takes multiple arguments, you can indicate position  
and type of these arguments in parentheses. In this way something(1i),  
something(2s), something(3f) are mapped to

Something.new(  
\<fixnum-value-of-param-something(1i)\>,  
\<string-value-of-param-something(2s)\>,  
\<float-value-of-param-something(3f)\>)

Michael

–  
Michael S.  
[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.schuerig.de/michael/](http://www.schuerig.de/michael/)

---

<div class="post-metadata">

**Author:** ![sw0rdfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@sw0rdfish](https://www.ruby-forum.com/u/sw0rdfish)\
**Post date:** [September 14, 2006, 6:41pm UTC](https://www.ruby-forum.com/t/multiple-text-field-for-one-variable/68556/4 "2006-09-14T18:41:48Z")

</div>

sw0rdfish wrote:

> Is there a way to have a model’s variable set using multiople text\_fields

Use ActiveRecord’s before\_create method in your model to combine two  
integer values into a single time property.

---

<div class="post-metadata">

**Author:** ![sw0rdfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@sw0rdfish](https://www.ruby-forum.com/u/sw0rdfish)\
**Post date:** [September 28, 2006, 4:54am UTC](https://www.ruby-forum.com/t/multiple-text-field-for-one-variable/68556/5 "2006-09-28T04:54:45Z")

</div>

Forgot to thank you guys!

I haven’t had a chance to test it, I’ve been fixing some real sloppy  
coding… but it makes perfect sense… I’ll report back incase somone  
else cares 🙂

---

<div class="post-metadata">

**Author:** ![sw0rdfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@sw0rdfish](https://www.ruby-forum.com/u/sw0rdfish)\
**Post date:** [September 13, 2006, 11:38pm UTC](https://www.ruby-forum.com/t/multiple-text-field-for-one-variable/68556/6 "2006-09-13T23:38:34Z")

</div>

On Wednesday 13 September 2006 23:16, Michael S. wrote:

> Basically, if you have an aggregation defined where the constructor  
> of the aggregate class takes multiple arguments, …

Forget about aggregations. Yes, it works for them, of course, but the  
point is really to supply the multiple arguments needed by the  
constructor of a class-valued (i.e. not String, Fixnum and cousins)  
attribute.

Michael

–  
Michael S.  
[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.schuerig.de/michael/](http://www.schuerig.de/michael/)
