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

Merge pull request #19844 from stevenspiel/link_to_if_block_helper_addition

Update url_helper.rb
This commit is contained in:
Yves Senn 2015-05-01 10:50:01 +02:00
commit d459b001b4
3 changed files with 10 additions and 1 deletions

View file

@ -1,3 +1,7 @@
* `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.

View file

@ -410,7 +410,7 @@ module ActionView
# # => <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)

View file

@ -379,6 +379,11 @@ class UrlHelperTest < ActiveSupport::TestCase
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)