# Multiparameter assignment

**URL:** <https://www.ruby-forum.com/t/multiparameter-assignment/53256>\
**Category:** Rails\
**Created:** [January 30, 2006, 5:54pm UTC](https://www.ruby-forum.com/t/multiparameter-assignment/53256 "2006-01-30T17:54:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![flw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/51bf81/32.png) [@flw](https://www.ruby-forum.com/u/flw)\
**Post date:** [January 30, 2006, 5:54pm UTC](https://www.ruby-forum.com/t/multiparameter-assignment/53256/1 "2006-01-30T17:54:00Z")

</div>

I’m trying to figure out the rails why to break a single database field  
out into multiple fields on a form, very similar to how rails does with  
dates. How can I create my own object that mirrors the date objects  
behaviur in how it accepts the multiparameter assignment from the form.

Example:  
A phone number field (to force formating on the user) could be broken  
into 3 form fields, formated server side, and written to the database in  
a single field.

---

<div class="post-metadata">

**Author:** ![flw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/51bf81/32.png) [@flw](https://www.ruby-forum.com/u/flw)\
**Post date:** [January 30, 2006, 6:04pm UTC](https://www.ruby-forum.com/t/multiparameter-assignment/53256/2 "2006-01-30T18:04:31Z")

</div>

On Mon, 2006-01-30 at 17:54 +0100, Fred Wittekind wrote:

> I’m trying to figure out the rails why to break a single database field  
> out into multiple fields on a form, very similar to how rails does with  
> dates. How can I create my own object that mirrors the date objects  
> behaviur in how it accepts the multiparameter assignment from the form.
> 
> Example:  
> A phone number field (to force formating on the user) could be broken  
> into 3 form fields, formated server side, and written to the database in  
> a single field.

* * *

there are helpers for phone numbers…  
\<%= number\_to\_phone(212-555-1212) %\>  
212-555-1212

there are validation methods such as validates\_format\_of attr, :with =\>  
regexp (pages 266 - 274 of Agile book)

there is also a section on ‘aggregation’ in Agile book that discusses  
handling/joining/separating strings (pages 257 - 263)

Craig

---

<div class="post-metadata">

**Author:** ![flw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/51bf81/32.png) [@flw](https://www.ruby-forum.com/u/flw)\
**Post date:** [January 30, 2006, 10:17pm UTC](https://www.ruby-forum.com/t/multiparameter-assignment/53256/3 "2006-01-30T22:17:31Z")

</div>

Fred Wittekind wrote:

> > > A phone number field (to force formating on the user) could be broken  
> > > displays 3 text enty fields. I think I can write this helper though, if  
> > > there is also a section on ‘aggregation’ in Agile book that discusses  
> > > Craig

I think aggregation is more about having _multiple_ database columns  
that you want to  
group into a child object for convenience sake… not taking a single  
column and  
presenting it as multiple input boxes on a form. Sounds like a helper to  
me.

b

---

<div class="post-metadata">

**Author:** ![flw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/51bf81/32.png) [@flw](https://www.ruby-forum.com/u/flw)\
**Post date:** [January 30, 2006, 10:24pm UTC](https://www.ruby-forum.com/t/multiparameter-assignment/53256/4 "2006-01-30T22:24:44Z")

</div>

Ben M. wrote:

> I think aggregation is more about having _multiple_ database columns  
> that you want to  
> group into a child object for convenience sake… not taking a single  
> column and  
> presenting it as multiple input boxes on a form. Sounds like a helper to  
> me.

Yeah, the aggregation didn’t work very well. I know I need the helper  
portion of this, and I even think I know how to do that part. The part  
I can’t figure out, is how to handle it properly in the model, to put it  
back together into a single field to write back to the database.

---

<div class="post-metadata">

**Author:** ![flw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/51bf81/32.png) [@flw](https://www.ruby-forum.com/u/flw)\
**Post date:** [January 30, 2006, 6:14pm UTC](https://www.ruby-forum.com/t/multiparameter-assignment/53256/5 "2006-01-30T18:14:41Z")

</div>

Craig W. wrote:

> On Mon, 2006-01-30 at 17:54 +0100, Fred Wittekind wrote:
> 
> > I’m trying to figure out the rails why to break a single database field  
> > out into multiple fields on a form, very similar to how rails does with  
> > dates. How can I create my own object that mirrors the date objects  
> > behaviur in how it accepts the multiparameter assignment from the form.
> > 
> > Example:  
> > A phone number field (to force formating on the user) could be broken  
> > into 3 form fields, formated server side, and written to the database in  
> > a single field.
> 
> * * *
> 
> there are helpers for phone numbers…  
> \<%= number\_to\_phone(212-555-1212) %\>  
> 212-555-1212

For what I’m trying to do, I need a form phone number helper, that  
displays 3 text enty fields. I think I can write this helper though, if  
I can figure out the rest of this.

> there are validation methods such as validates\_format\_of attr, :with =\>  
> regexp (pages 266 - 274 of Agile book)

I’m sure I will have to address validation, but not ready for that yet.

> there is also a section on ‘aggregation’ in Agile book that discusses  
> handling/joining/separating strings (pages 257 - 263)

I’ve looked at the section on aggregation, and tried very unsuccessfully  
at doing this with a composed\_of aggregation. I got as far as the form  
helper working, but as soon as I hit submit, it got a multiparameter  
assignment error. It looked like ActiveRecord couldn’t figure out where  
the object used in the aggregation was defined.

> Craig
