aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionview/lib/action_view/helpers/url_helper.rb6
-rw-r--r--actionview/test/template/url_helper_test.rb7
2 files changed, 12 insertions, 1 deletions
diff --git a/actionview/lib/action_view/helpers/url_helper.rb b/actionview/lib/action_view/helpers/url_helper.rb
index 19e5941971..bfd154abec 100644
--- a/actionview/lib/action_view/helpers/url_helper.rb
+++ b/actionview/lib/action_view/helpers/url_helper.rb
@@ -180,7 +180,11 @@ module ActionView
url = url_for(options)
html_options['href'] ||= url
- content_tag(:a, name || url, html_options, &block)
+ if block_given?
+ content_tag(:a, capture(&block) || url, html_options)
+ else
+ content_tag(:a, name || url, html_options)
+ end
end
# Generates a form containing a single button that submits to the URL created
diff --git a/actionview/test/template/url_helper_test.rb b/actionview/test/template/url_helper_test.rb
index 54747fe079..851ea8796f 100644
--- a/actionview/test/template/url_helper_test.rb
+++ b/actionview/test/template/url_helper_test.rb
@@ -308,6 +308,13 @@ class UrlHelperTest < ActiveSupport::TestCase
link_to('/', class: "special") { content_tag(:span, 'Example site') }
end
+ def test_link_tag_using_block_and_hash
+ assert_dom_equal(
+ %{<a href="/"><span>Example site</span></a>},
+ link_to(url_hash) { content_tag(:span, 'Example site') }
+ )
+ end
+
def test_link_tag_using_block_in_erb
out = render_erb %{<%= link_to('/') do %>Example site<% end %>}
assert_equal '<a href="/">Example site</a>', out