Skip to content

Instantly share code, notes, and snippets.

@yosiyuki
Created October 27, 2012 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yosiyuki/3965495 to your computer and use it in GitHub Desktop.
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)
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