# Help --- My phone number field saves blank

**URL:** <https://www.ruby-forum.com/t/help-my-phone-number-field-saves-blank/168758>\
**Category:** Rails\
**Created:** [May 25, 2009, 2:00pm UTC](https://www.ruby-forum.com/t/help-my-phone-number-field-saves-blank/168758 "2009-05-25T14:00:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [May 25, 2009, 2:00pm UTC](https://www.ruby-forum.com/t/help-my-phone-number-field-saves-blank/168758/1 "2009-05-25T14:00:38Z")

</div>

I have a phone field in my table.  
But in my form i have two text boxes to get the phone number and the  
country code like below

Enter country code ----- Enter phone code ------

In my table i have to save the phone code field after joining the above  
values with “-” symbol.

Example =\> 0225-25874255

I dont have table field for country\_code .  
So i created like below  
attr\_accessor :phone , :country\_code  
I have given for validation like below

validates\_presence\_of :country\_code,  
:message =\> ‘\*The country code is required.’

@user = UserInfo.new()  
phone\_code = params[:userinfo][:country\_code] +’-’+  
params[:userinfo][:phone\_code]  
@user.name = params[:userinfo][:name]  
@user.phone = phone\_code  
@user.save  
when i save,my phone field is blank…  
what i m doing wrong…  
pls guide me.

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [May 25, 2009, 2:22pm UTC](https://www.ruby-forum.com/t/help-my-phone-number-field-saves-blank/168758/2 "2009-05-25T14:22:20Z")

</div>

On May 25, 1:00 pm, Newb N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I dont have table field for country\_code .  
> So i created like below  
> attr\_accessor :phone , :country\_code

You don’t need attr\_accessor for :phone since you already have a phone  
column (if i understand correctly). When used like this attr\_accessor  
overwrites the accessors that ActiveRecord provides.

Fred
