# Combining 2 hash fields in a single database field

**URL:** <https://www.ruby-forum.com/t/combining-2-hash-fields-in-a-single-database-field/191923>\
**Category:** Rails\
**Created:** [July 20, 2010, 6:07pm UTC](https://www.ruby-forum.com/t/combining-2-hash-fields-in-a-single-database-field/191923 "2010-07-20T18:07:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sachin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c77e96/32.png) [@sachin](https://www.ruby-forum.com/u/sachin)\
**Post date:** [July 20, 2010, 6:07pm UTC](https://www.ruby-forum.com/t/combining-2-hash-fields-in-a-single-database-field/191923/1 "2010-07-20T18:07:21Z")

</div>

Hello Gurus,  
I have a form which has a phone\_no field. I want to provide 3 text  
fields to user to split and enter the phone number in country\_code,  
state\_code and the number which will be contacted and entered in to  
the phone\_no field with some delimiter (-)

The same functionality will be for address\_1, and address\_2 fields,  
which will be merged in to a single address field.  
any pointers suggestions to implement this functionality.

Thanks in advance

- S

---

<div class="post-metadata">

**Author:** ![sachin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c77e96/32.png) [@sachin](https://www.ruby-forum.com/u/sachin)\
**Post date:** [July 20, 2010, 7:15pm UTC](https://www.ruby-forum.com/t/combining-2-hash-fields-in-a-single-database-field/191923/2 "2010-07-20T19:15:17Z")

</div>

Sachin wrote:

> Hello Gurus,  
> I have a form which has a phone\_no field. I want to provide 3 text  
> fields to user to split and enter the phone number in country\_code,  
> state\_code and the number which will be contacted and entered in to  
> the phone\_no field with some delimiter (-)
> 
> The same functionality will be for address\_1, and address\_2 fields,  
> which will be merged in to a single address field.  
> any pointers suggestions to implement this functionality.

Just munge the strings in the model’s before\_save or constructor.

> Thanks in advance
> 
> - S

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![sachin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c77e96/32.png) [@sachin](https://www.ruby-forum.com/u/sachin)\
**Post date:** [July 21, 2010, 7:11am UTC](https://www.ruby-forum.com/t/combining-2-hash-fields-in-a-single-database-field/191923/3 "2010-07-21T07:11:47Z")

</div>

Thanks for the pointer Marnen, i shall try it out.

- S
