aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing/url_for.rb
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2010-07-01 09:04:30 +0200
committerPiotr Sarnacki <drogus@gmail.com>2010-09-03 22:59:05 +0200
commit28016d33b0f2e668ca59a912c7fb2d777e3cf0a3 (patch)
treec5b20887fe18aef91b560d8c1d7bf11863867380 /actionpack/lib/action_dispatch/routing/url_for.rb
parent32a5b49911b88e8e410583d382e8253004abce50 (diff)
downloadrails-28016d33b0f2e668ca59a912c7fb2d777e3cf0a3.tar.gz
rails-28016d33b0f2e668ca59a912c7fb2d777e3cf0a3.tar.bz2
rails-28016d33b0f2e668ca59a912c7fb2d777e3cf0a3.zip
Use env['action_dispatch.routes'] to determine if we should generate prefix or not.
This technique is here to allow using routes from Engine in Application and vice versa. When using Engine routes inside Application it should generate prefix based on mount point. When using Engine routes inside Engine it should use env['SCRIPT_NAME']. In any other case it should generate prefix as env should not be even available.
Diffstat (limited to 'actionpack/lib/action_dispatch/routing/url_for.rb')
-rw-r--r--actionpack/lib/action_dispatch/routing/url_for.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb
index 28ec830fe8..f73067688c 100644
--- a/actionpack/lib/action_dispatch/routing/url_for.rb
+++ b/actionpack/lib/action_dispatch/routing/url_for.rb
@@ -128,7 +128,13 @@ module ActionDispatch
when String
options
when nil, Hash
- _routes.url_for((options || {}).reverse_merge!(url_options).symbolize_keys)
+ routes = (options ? options.delete(:routes) : nil) || _routes
+
+ if respond_to?(:env) && env && routes.equal?(env["action_dispatch.routes"])
+ options[:skip_prefix] = true
+ end
+
+ routes.url_for((options || {}).reverse_merge!(url_options).symbolize_keys)
else
polymorphic_url(options)
end