diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-07-17 10:47:58 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-07-17 10:47:58 -0700 |
commit | 2888f8653e2e0a6394e41cb4e8db2e2d81313eb7 (patch) | |
tree | 799fa297dcc3054307a759f64cb7edff19b9e8af /actionpack/lib/action_dispatch/http/url.rb | |
parent | a9765c54ea17153a69932730e1f5291c1f0055b0 (diff) | |
download | rails-2888f8653e2e0a6394e41cb4e8db2e2d81313eb7.tar.gz rails-2888f8653e2e0a6394e41cb4e8db2e2d81313eb7.tar.bz2 rails-2888f8653e2e0a6394e41cb4e8db2e2d81313eb7.zip |
use a strategy object for generating urls in named helpers
since we know that the route should be a path or fully qualified, we can
pass a strategy object that handles generation. This allows us to
eliminate an "if only_path" branch when generating urls.
Diffstat (limited to 'actionpack/lib/action_dispatch/http/url.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/http/url.rb | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/actionpack/lib/action_dispatch/http/url.rb b/actionpack/lib/action_dispatch/http/url.rb index 5decab3d8f..473f692b05 100644 --- a/actionpack/lib/action_dispatch/http/url.rb +++ b/actionpack/lib/action_dispatch/http/url.rb @@ -29,20 +29,25 @@ module ActionDispatch end def url_for(options) - host = options[:host] - unless host || options[:only_path] - 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)) + full_url_for options end end + def full_url_for(options) + host = options[:host] + protocol = options[:protocol] + port = options[:port] + + unless host + raise ArgumentError, 'Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true' + end + + build_host_url(host, port, protocol, options, path_for(options)) + end + def path_for(options) result = options[:script_name].to_s.chomp("/") result << options[:path].to_s |