Created
October 27, 2012 17:51
-
-
Save yosiyuki/3965495 to your computer and use it in GitHub Desktop.
automatically add link text to link_to (though this code force-update original link_to)
This file contains 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
module ActionView | |
module Helpers | |
module UrlHelper | |
alias original_link_to link_to | |
def link_to(*args, &block) | |
if block_given? | |
options = args.first || {} | |
html_options = args.second | |
link_to(capture(&block), options, html_options) | |
else | |
html_options = args[2] | |
unless is_tag?(args[0]) | |
if html_options.nil? | |
html_options = { title: args[0] } | |
elsif not html_options.has_key?('title') | |
html_options['title'] = args[0] | |
end | |
end | |
original_link_to args[0], args[1], html_options | |
end | |
end | |
def is_tag? str | |
str.match /^</ | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment