Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #14421 from davidpdrsn/reorder-conditionals

Reorder conditional logic in link_to_if and link_to_unless
  • Loading branch information...
commit 8cea8ae278c0e0417e5d58a387cc5d31c0590251 2 parents 4279a75 + 4f90298
@rafaelfranca rafaelfranca authored
Showing with 10 additions and 10 deletions.
  1. +10 −10 actionview/lib/action_view/helpers/url_helper.rb
View
20 actionview/lib/action_view/helpers/url_helper.rb
@@ -389,15 +389,7 @@ def link_to_unless_current(name, options = {}, html_options = {}, &block)
# # If not...
# # => <a href="/accounts/signup">Reply</a>
def link_to_unless(condition, name, options = {}, html_options = {}, &block)
- if condition
- if block_given?
- block.arity <= 1 ? capture(name, &block) : capture(name, options, html_options, &block)
- else
- ERB::Util.html_escape(name)
- end
- else
- link_to(name, options, html_options)
- end
+ link_to_if !condition, name, options, html_options, &block
end
# Creates a link tag of the given +name+ using a URL created by the set of
@@ -421,7 +413,15 @@ def link_to_unless(condition, name, options = {}, html_options = {}, &block)
# # If they are logged in...
# # => <a href="/accounts/show/3">my_username</a>
def link_to_if(condition, name, options = {}, html_options = {}, &block)
- link_to_unless !condition, name, options, html_options, &block
+ if condition
+ link_to(name, options, html_options)
+ else
+ if block_given?
+ block.arity <= 1 ? capture(name, &block) : capture(name, options, html_options, &block)
+ else
+ ERB::Util.html_escape(name)
+ end
+ end
end
# Creates a mailto link tag to the specified +email_address+, which is
Please sign in to comment.
Something went wrong with that request. Please try again.