I'm new to Rails, and so far I love it, but I'm having a problem. I have a phone_numbers table that has a number field, which holds the phone number for that record. I have also written a view which has three fields in it: area_code, prefix, and suffix. None of these fields exist in the phone_numbers table, but I wanted to break them up in the view so that I could have each one be an individual text field. In the phone_numbers model I have defined a before_create method like so:
attr_accessor :area_code, :prefix, :suffix
def before_create
number = [self.area_code, self.prefix, self.suffix].compact.join
end
This works fine, but I want to validate that area_code, prefix, and suffix are all numbers, so I tried using validates_numericality_of :area_code, :prefix, :suffix, but it is not working. I keep getting an error which states the following:
NoMethodError in UserController#save_user
undefined method `area_code_before_type_cast' for #<PhoneNumber:0x510d27c>
How can I fix this. As a side note, the validates_presence_of :area_code, :prefix, :suffix is working fine.
Thank you for your help.