From 451c9942bb493190d5673c1b55be7506056db13b Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 7 Jul 2010 11:26:03 +0200 Subject: Allow to generate Application routes inside Engine This requires knowledge about original SCRIPT_NAME and the parent router. It should be pass through the env as ORIGIAL_SCRIPT_NAME and action_dispatch.parent_routes --- actionpack/lib/action_dispatch/routing/mapper.rb | 2 +- actionpack/lib/action_dispatch/routing/url_for.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index f3aa09f4a7..0e138524cd 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -289,7 +289,7 @@ module ActionDispatch app.routes.class_eval do define_method :_generate_prefix do |options| keys = _route.segment_keys + ActionDispatch::Routing::RouteSet::RESERVED_OPTIONS - prefix_options = options.reject { |k, v| !(keys).include?(k) } + prefix_options = options.slice(*keys) # we must actually delete prefix segment keys to avoid passing them to next url_for _route.segment_keys.each { |k| options.delete(k) } _router.url_helpers.send("#{name}_path", prefix_options) diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb index f73067688c..deaf1cdf03 100644 --- a/actionpack/lib/action_dispatch/routing/url_for.rb +++ b/actionpack/lib/action_dispatch/routing/url_for.rb @@ -129,9 +129,9 @@ module ActionDispatch options when nil, Hash routes = (options ? options.delete(:routes) : nil) || _routes - - if respond_to?(:env) && env && routes.equal?(env["action_dispatch.routes"]) - options[:skip_prefix] = true + if respond_to?(:env) && env + options[:skip_prefix] = true if routes.equal?(env["action_dispatch.routes"]) + options[:script_name] = env["ORIGINAL_SCRIPT_NAME"] if routes.equal?(env["action_dispatch.parent_routes"]) end routes.url_for((options || {}).reverse_merge!(url_options).symbolize_keys) -- cgit v1.2.3