Forum: Ruby on Rails Help --- My phone number field saves blank

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Newb N. (Guest)
on 2009-05-25 16:00
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.
Frederick C. (Guest)
on 2009-05-25 16:22
(Received via mailing list)
On May 25, 1:00 pm, Newb N. <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
This topic is locked and can not be replied to.