Created
October 6, 2014 21:18
-
-
Save wingrunr21/8fc9e8d31005acf2bd7b to your computer and use it in GitHub Desktop.
Rails helper that will create tel: style anchor tags in a similar fashion as to how the link_to Rails helper operates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment