I'm trying to figure out a good way to store phone numbers as an integer
in a rails app without having to have separate columns in the table for
each part of the phone number. I want people to enter the phone number
in a single entry field, but to be able to store it as an integer rather
than as a string.
My idea was to allow free-form text entry in the form, but to add
something into create() to turn the string into an integer. From the
console, though:
>> @foo=User.new
>> @foo.build_contact
>> @foo.contact.phone='123-456-7890'
>> p @foo.contact.phone
=> 123
Obviously, rails is converting the string to an integer before saving it
to the database, but this doesn't get me where I need to go. My idea was
to simply add some evaluation in create like:
@foo.contact.phone.gsub([^\d]+, '')
but this obviously isn't going to work. So, if my model defines
contact.phone as an integer, how can I coerce numbers entered from the
new/edit views into the appropriate data type?
--
"Oh, look: rocks!"
-- Doctor Who, "Destiny of the Daleks"
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---