Attribute Accessors for Phone Number in Form

hello,

I have a field in the DB called phone_number , string 10 chars. In
my form i want to make these 3 text boxes (phone1, phone2, phone3). I
am trying to figure out how to assemble this to create the phone
number before saving. I am trying the following:

In the model

before_save :make_phone

def phone1
end

def phone2
end

def phone3
end

def phone1=(p1)
end

def phone2=(p2)
end

def phone3=(p3)
end

  def make_phone
   self.phone_number = phone1 + phone2 + phon3
  end

however i dont seem to have access to params[:model][:phone1] from
here. Any ideas on how to make this work ?

Thanks

hello,

I have a field in the DB called phone_number , string 10 chars. In

my form i want to make these 3 text boxes (phone1, phone2, phone3). I

am trying to figure out how to assemble this to create the phone

number before saving. I am trying the following:

In the model

before_save :make_phone

def phone1

end

def phone2

end

def phone3

end

def phone1=(p1)

end

def phone2=(p2)

end

def phone3=(p3)

end

def make_phone

self.phone_number = phone1 + phone2 + phon3

end

however i dont seem to have access to params[:model][:phone1] from

here. Any ideas on how to make this work ?

Thanks

Hi, what does your param hash look like when you submit the form?

-Conrad

Your attribute writer methods don't do anything at the moment. They'll
have to set instance variables which can be accessed by the
before_save method. The attr_accessor shortcut can provide these.

You're looking for something like:

before_save :make_phone
attr_accessor :phone_1, :phone_2, :phone_3

def make_phone
  self.phone_number = @phone_1 + @phone_2 + @phone_3
end

-Matt