search for: format_phon

Displaying 3 results from an estimated 3 matches for "format_phon".

Did you mean: format_phone
2006 May 08
4
gsub no workie
...o work for me. I have a phone number field for an addressbook. In the addressbook model I have a before_update declaration that says the following: I''d like to be able to remove all special characters (just numbers please), but this doesn''t want to work for me. before_update :format_phone def format_phone self.phone = self.phone.to_s.gsub(/\D/, "") end The following works to remove all numbers, so I know it''s reaching the before_update call. :-) self.phone = self.phone.to_s.gsub(/\d/, "") Any help is appriciated. Thanks! -- Posted via http...
2006 May 09
11
model filter?
Hi All, Is there a way to filter / modify the output of a model class before it''s returned to controller/view that''s calling it? Example: I have a field phone_number which I always want to preformat using the number_to_phone() helper.... Any help is appriciated. Thanks! -- Posted via http://www.ruby-forum.com/.
2006 Nov 04
0
Validations ignoring :allow_nil => true
...rue. If I leave the phone input blank, I get it back with a "too short" error. Here''s the relevant parts of the model: 1. class Address < ActiveRecord::Base 2. 3. validates_length_of :phone, :in => 7..10, :allow_nil => true 4. 5. before_validation :format_phone 6. 7. def format_phone 8. unless self.phone.nil? 9. self.phone.gsub!( /[^0-9#\*]/, '''' ) 10. self.phone.gsub!( /^1/, '''' ) 11. end 12. end 13. 14. end So, why isn''t the model doing what it''s supposed to? Thanks,...