Skip to content

Instantly share code, notes, and snippets.

@wingrunr21
Created October 6, 2014 21:18
Show Gist options
  • Save wingrunr21/8fc9e8d31005acf2bd7b to your computer and use it in GitHub Desktop.
Save wingrunr21/8fc9e8d31005acf2bd7b to your computer and use it in GitHub Desktop.

Revisions

  1. wingrunr21 created this gist Oct 6, 2014.
    31 changes: 31 additions & 0 deletions phone_link_helper.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    # This module provides a Rails helper that will create tel: style
    # anchor tags in a similar fashion as to how the link_to Rails
    # helper operates
    #
    # Copyright (C) 2014 Turn4 LLC
    #
    # This program is free software: you can redistribute it and/or modify
    # it under the terms of the GNU General Public License as published by
    # the Free Software Foundation, either version 3 of the License, or
    # (at your option) any later version.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    # GNU General Public License for more details.
    #
    # You should have received a copy of the GNU General Public License
    # along with this program. If not, see <http://www.gnu.org/licenses/>.

    module PhoneLinkHelper
    def link_to_phone(text, options = {}, &blk)
    return "" if text.blank?
    number = number_to_phone(text, delimiter: options.fetch(:delimiter, '-'))
    href = "tel:#{number_to_phone(text, country_code:1)}"
    if block_given?
    link_to href, &blk
    else
    link_to number, href
    end
    end
    end