![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
@foo=User.new @foo.build_contact @foo.contact.phone='123-456-7890' p @foo.contact.phone => 123 |
#2
| |||
| |||
|
|
* *@foo.contact.phone.gsub([^\d]+, '') |
#3
| |||
| |||
|
|
On Wed, Nov 4, 2009 at 3:43 PM, Todd A. Jacobs tjacobs-sndr-b4faac (AT) codegnome (DOT) org> wrote: Â* Â*@foo.contact.phone.gsub([^\d]+, '') What about storing things like 123-123-1234 ext 123 ? A phone number isn't a number. |
#4
| |||
| |||
|
|
What is wrong with storing it as a string anyway? |
#5
| |||
| |||
|
|
What is wrong with storing it as a string anyway? |
|
foo = ActionView::Base.new foo.number_to_phone 1234567890, :area_code => true => "(123) 456-7890" |
|
foo.number_to_phone "123/456.7890x55", :area_code => true => "123/456.7890x55" |
#6
| |||
| |||
|
|
More importantly, though, if you store a number as varchar or text, you have a much harder time regularizing the output. For example, you couldn't do this: * >> *foo = ActionView::Base.new * >> foo.number_to_phone 1234567890, :area_code => true * => "(123) 456-7890" |
#7
| |||||
| |||||
|
|
On Wed, Nov 04, 2009 at 09:59:36PM +0000, Colin Law wrote: What is wrong with storing it as a string anyway? Strings are less efficient than integers, from a database point of view. |
|
More importantly, though, if you store a number as varchar or text, you have a much harder time regularizing the output. For example, you couldn't do this: foo = ActionView::Base.new foo.number_to_phone 1234567890, :area_code => true => "(123) 456-7890" |
|
with a random string. If you try, you just get back the original string, like so: foo.number_to_phone "123/456.7890x55", :area_code => true => "123/456.7890x55" |
|
The whole idea here is to regularize the data IN THE DATABASE, so that the output can be customized (and perhaps even changed later) without having to change the schema. Isn't there some way to strip out the characters and extra digits *after* form submission but *before* the assignment to the model object? |
|
-- "Oh, look: rocks!" -- Doctor Who, "Destiny of the Daleks" |
![]() |
| Thread Tools | |
| Display Modes | |
| |