1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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

Fix actionview link_to with block and url_hash
This commit is contained in:
Rafael Mendonça França 2013-07-07 10:02:39 -07:00
commit 9eeb3cc040
2 changed files with 8 additions and 1 deletions

View file

@ -172,7 +172,7 @@ module ActionView
# 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 file

@ -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