aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing/route_set.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_dispatch/routing/route_set.rb')
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb34
1 files changed, 14 insertions, 20 deletions
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index d380564c23..fd163a47f4 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -155,7 +155,7 @@ module ActionDispatch
end
def self.optimize_helper?(route)
- !route.glob? && route.requirements.except(:controller, :action).empty?
+ !route.glob? && route.requirements.except(:controller, :action, :host).empty?
end
class OptimizedUrlHelper < UrlHelper # :nodoc:
@@ -171,8 +171,7 @@ module ActionDispatch
def call(t, args)
if args.size == arg_size && !args.last.is_a?(Hash) && optimize_routes_generation?(t)
- options = @options.dup
- options.merge!(t.url_options)
+ options = t.url_options.merge @options
options[:path] = optimized_helper(args)
ActionDispatch::Http::URL.url_for(options)
else
@@ -225,22 +224,18 @@ module ActionDispatch
end
def call(t, args)
- options = handle_positional_args(t, args, @options, @segment_keys)
- hash = {
- :only_path => options[:host].nil?
- }.merge!(options.symbolize_keys)
- hash.reverse_merge!(t.url_options)
+ options = t.url_options.merge @options
+ hash = handle_positional_args(t, args, options, @segment_keys)
t._routes.url_for(hash)
end
- def handle_positional_args(t, args, options, keys)
+ def handle_positional_args(t, args, result, keys)
inner_options = args.extract_options!
- result = options.dup
if args.size > 0
if args.size < keys.size - 1 # take format into account
keys -= t.url_options.keys
- keys -= options.keys
+ keys -= result.keys
end
keys -= inner_options.keys
result.merge!(Hash[keys.zip(args)])
@@ -646,13 +641,13 @@ module ActionDispatch
!mounted? && default_url_options.empty?
end
- def _generate_prefix(options = {})
- nil
+ def find_script_name(options)
+ options.delete :script_name
end
- # The +options+ argument must be +nil+ or a hash whose keys are *symbols*.
+ # The +options+ argument must be a hash whose keys are *symbols*.
def url_for(options)
- options = default_url_options.merge(options || {})
+ options = default_url_options.merge options
user = password = nil
@@ -661,10 +656,10 @@ module ActionDispatch
password = options.delete :password
end
- recall = options.delete(:_recall)
+ recall = options.delete(:_recall) { {} }
- original_script_name = options.delete(:original_script_name).presence
- script_name = options.delete(:script_name).presence || _generate_prefix(options)
+ original_script_name = options.delete(:original_script_name)
+ script_name = find_script_name options
if script_name && original_script_name
script_name = original_script_name + script_name
@@ -672,9 +667,8 @@ module ActionDispatch
path_options = options.dup
RESERVED_OPTIONS.each { |ro| path_options.delete ro }
- path_options = yield(path_options) if block_given?
- path, params = generate(path_options, recall || {})
+ path, params = generate(path_options, recall)
params.merge!(options[:params] || {})
ActionDispatch::Http::URL.url_for(options.merge!({