Call Me! A quick how-to for getting dialable phone numbers in your Rails app.
January 22nd, 2008 byThis might be something everyone knows but just in case I figured I would post a quick how-to on getting a clickable phone number in your Rails app. This example is only for the iPhone user_agent but you can make it work for other types as well as long as you know the user_agent.
Place the following code snippet in your application.rb file
session :mobile => true, :if => proc { |request| Utility.mobile?(request.user_agent) }
class Utility
def self.mobile?(user_agent)
user_agent =~/(iPhone)/i
end
end
Then in your view or your presenter code put a check for the session variable and if it is set then display the clickable phone number with the tel protocol in the href like so
"tel:#{contact.phone}"
and if its not set then just do things normally. Make sure you have the check there because if you don’t then when someone clicks the link in the browser it will complain about not understanding the tel protocol.


January 22nd, 2008 at 11:37 am
I’m just as interested in the opposite. My Treo tries to turn every string of numbers it displays into a tel: tag. This is very annoying for our web application, which displays things like “Unique Well Identifiers” (Oil&Gas) that look like this - 07-08-003-30W4, and get turned into clickable tel links (which, of course, don’t work).
February 8th, 2008 at 9:03 am
Lori,
Perhaps you can take a page from the tricks of the email spammers to stop the clickability of those numbers by inserting tags that effectively do nothing in the middle of those numbers? Like: <span>07</span>-<span>08</span>-<span>003</span>-<span>30W4</span>