Skip to content
Browse files

Merge pull request #11348 from sanemat/fix/link-to-block

Fix actionview link_to with block and url_hash
  • Loading branch information...
2 parents 09f6fe1 + bcc30d8 commit 9eeb3cc040f9ab701279d73aa76f12737cedd3fb @rafaelfranca rafaelfranca committed Jul 7, 2013
View
2 actionview/lib/action_view/helpers/url_helper.rb
@@ -172,7 +172,7 @@ def _back_url # :nodoc:
# link_to "Visit Other Site", "http://www.rubyonrails.org/", data: { confirm: "Are you sure?" }
# # => <a href="http://www.rubyonrails.org/" data-confirm="Are you sure?">Visit Other Site</a>
def link_to(name = nil, options = nil, html_options = nil, &block)
- html_options, options = options, name if block_given?
+ html_options, options, name = options, name, block if block_given?
options ||= {}
html_options = convert_options_to_data_attributes(options, html_options)
View
7 actionview/test/template/url_helper_test.rb
@@ -308,6 +308,13 @@ def test_link_tag_with_block_and_html_options
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

0 comments on commit 9eeb3cc

Please sign in to comment.
Something went wrong with that request. Please try again.