From 4f90298d3752bb244d882374b16a0c6b06932b31 Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Tue, 18 Mar 2014 21:16:36 +0100 Subject: Reorder conditional logic According to the best practice that "unless not" and "unless else" is hard to follow logically the link_to_unless and link_to_if were reversed. --- actionview/lib/action_view/helpers/url_helper.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'actionview/lib/action_view/helpers/url_helper.rb') diff --git a/actionview/lib/action_view/helpers/url_helper.rb b/actionview/lib/action_view/helpers/url_helper.rb index 51379d433f..89c196e578 100644 --- a/actionview/lib/action_view/helpers/url_helper.rb +++ b/actionview/lib/action_view/helpers/url_helper.rb @@ -389,15 +389,7 @@ module ActionView # # If not... # # => Reply 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 @@ module ActionView # # If they are logged in... # # => my_username 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 -- cgit v1.2.3