提交 14d0e070 编写于 作者: Y Yves Senn

Revert "Merge pull request #19844 from stevenspiel/link_to_if_block_helper_addition"

This reverts commit d459b001, reversing
changes made to 4d4950fa.

😓

The block is not supposed to be passed to `link_to`. It's used for a
customized behavior of the `condtion = false` case. The docs
illustrate that like so:

```
<%=
   link_to_if(@current_user.nil?, "Login", { controller: "sessions", action: "new" }) do
     link_to(@current_user.login, { controller: "accounts", action: "show", id: @current_user })
   end
%>
```
上级 d459b001
* `link_to_if` passes the block along.
*Steven Spiel*
* Load the `default_form_builder` from the controller on initialization, which overrides
the global config if it is present.
......
......@@ -410,7 +410,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, &block)
link_to(name, options, html_options)
else
if block_given?
block.arity <= 1 ? capture(name, &block) : capture(name, options, html_options, &block)
......
......@@ -379,11 +379,6 @@ 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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册