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.
on 2009-05-25 16:00
on 2009-05-25 16:22
On May 25, 1:00 pm, Newb N. <firstname.lastname@example.org> 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