# Question on model and fields in form

**URL:** <https://www.ruby-forum.com/t/question-on-model-and-fields-in-form/151212>\
**Category:** Rails\
**Created:** [October 18, 2008, 6:39am UTC](https://www.ruby-forum.com/t/question-on-model-and-fields-in-form/151212 "2008-10-18T06:39:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![inrila](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a3d4f5/32.png) [@inrila](https://www.ruby-forum.com/u/inrila)\
**Post date:** [October 18, 2008, 6:39am UTC](https://www.ruby-forum.com/t/question-on-model-and-fields-in-form/151212/1 "2008-10-18T06:39:08Z")

</div>

Hi there,

Her is the thing.

Let’s say, I have model “Phonebook”, which has two fields “phone\_number”  
and “full\_name”.

I also have view, with form which asks for “full\_name” and (important  
here) couple of fields:

phone\_int  
phone\_area  
phone\_number  
phone\_extension

They all need to be concated like

phone\_int (phone\_area) phone\_number ext. phone\_extension

i.e.

phone\_int = +1  
phone\_area = 415  
phone\_number = 321-2345  
phone\_extension = 101

it need to become

phone\_number = +1 (415) 321-2345 ext. 101

Do not ask me why the hell am I doing this thing, it’s just an example,  
and yes, there are some legacy database structure cases where something  
like that has to be done 🙂

So here in controller I am doing  
@phonebook.update\_attributes(params[:phonebook]) and fields phone\_int,  
phone\_area, phone\_number, phone\_extension are defined with attr\_accessor  
in the model.

So, where do I do the concatenation process? In the model? Do I do it  
before calling update\_attributes in controller? What will be the best  
practice?

I see it can have it place in the model, but where should I put it  
exactly so it’ll work out before update\_attributes?

Thanks!

---

<div class="post-metadata">

**Author:** ![inrila](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a3d4f5/32.png) [@inrila](https://www.ruby-forum.com/u/inrila)\
**Post date:** [October 18, 2008, 10:03am UTC](https://www.ruby-forum.com/t/question-on-model-and-fields-in-form/151212/2 "2008-10-18T10:03:35Z")

</div>

In the model do

before\_save :concat\_phonenumbers

def concat\_phonenumbers  
self.phone\_number = "#{phone\_int} " + "#{phone\_area} " +  
"#{phone\_number} " + “#{phone\_extension}”  
end
