From 0e26271456a772de5ce4c4c78cce3a275bcb89a8 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 16 Jul 2014 18:15:15 -0700 Subject: extract path building to a method --- actionpack/lib/action_dispatch/http/url.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'actionpack/lib/action_dispatch/http') diff --git a/actionpack/lib/action_dispatch/http/url.rb b/actionpack/lib/action_dispatch/http/url.rb index fc1d0e6663..5decab3d8f 100644 --- a/actionpack/lib/action_dispatch/http/url.rb +++ b/actionpack/lib/action_dispatch/http/url.rb @@ -34,21 +34,23 @@ module ActionDispatch raise ArgumentError, 'Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true' end + if options[:only_path] + path_for options + else + protocol = options[:protocol] + port = options[:port] + build_host_url(host, port, protocol, options, path_for(options)) + end + end + + def path_for(options) result = options[:script_name].to_s.chomp("/") result << options[:path].to_s result = add_trailing_slash(result) if options[:trailing_slash] result = add_params options, result - result = add_anchor options, result - - if options[:only_path] - result - else - protocol = options[:protocol] - port = options[:port] - build_host_url(host, port, protocol, options, result) - end + add_anchor options, result end private -- cgit v1.2.3