Skip to content

Commit

Permalink
Merge pull request #19844 from stevenspiel/link_to_if_block_helper_ad…
Browse files Browse the repository at this point in the history
…dition

Update url_helper.rb

Conflicts:
	actionview/CHANGELOG.md
  • Loading branch information
senny committed May 1, 2015
1 parent b081eda commit 78121ff
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions actionview/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* `link_to_if` passes the block along.

*Steven Spiel*

* `translate` allows `default: [[]]` again for a default value of `[]`.

Fixes #19640.
Expand Down
2 changes: 1 addition & 1 deletion actionview/lib/action_view/helpers/url_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def link_to_unless(condition, name, options = {}, html_options = {}, &block)
# # => <a href="/accounts/show/3">my_username</a>
def link_to_if(condition, name, options = {}, html_options = {}, &block)
if condition
link_to(name, options, html_options)
link_to(name, options, html_options, &block)
else
if block_given?
block.arity <= 1 ? capture(name, &block) : capture(name, options, html_options, &block)
Expand Down
5 changes: 5 additions & 0 deletions actionview/test/template/url_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,11 @@ def test_link_to_if
assert_dom_equal %{<a href="/">Listing</a>}, link_to_if(true, "Listing", url_hash)
end

def test_link_to_if_with_block
assert_equal "Block Showing", link_to_if(false, url_hash) { "Block Showing" }
assert_dom_equal %{<a href="/">Block Listing</a>}, link_to_if(true, url_hash) { "Block Listing" }
end

def request_for_url(url, opts = {})
env = Rack::MockRequest.env_for("http://www.example.com#{url}", opts)
ActionDispatch::Request.new(env)
Expand Down

0 comments on commit 78121ff

Please sign in to comment.