CONTENTS OF THIS SITE

OUR OTHER CONTENTS

RECENT BLOG ENTRIES

Call Me! A quick how-to for getting dialable phone numbers in your Rails app.

January 22nd, 2008 by comment desi

This 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.

Comments

2 Responses to “Call Me! A quick how-to for getting dialable phone numbers in your Rails app.”

  1. Lori M Olson says:


    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).

  2. Cosine Jeremiah says:


    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>

Got something to say?