aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing/url_for.rb
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2010-07-08 15:42:40 +0200
committerPiotr Sarnacki <drogus@gmail.com>2010-09-03 22:59:05 +0200
commiteedbf87d15b99a7cae38b0d8894fc39f1e70a81e (patch)
tree97fe871d6c640c6b83e7956396cd60b0c42b1d67 /actionpack/lib/action_dispatch/routing/url_for.rb
parent177a4bd5b7f903030a100f9b5092b1fa62c7c748 (diff)
downloadrails-eedbf87d15b99a7cae38b0d8894fc39f1e70a81e.tar.gz
rails-eedbf87d15b99a7cae38b0d8894fc39f1e70a81e.tar.bz2
rails-eedbf87d15b99a7cae38b0d8894fc39f1e70a81e.zip
New way of generating urls for Application from Engine.
It's based specifying application's script_name with: Rails.application.default_url_options = {:script_name => "/foo"} default_url_options method is delegated to routes. If router used to generate url differs from the router passed via env it always overwrites :script_name with this value.
Diffstat (limited to 'actionpack/lib/action_dispatch/routing/url_for.rb')
-rw-r--r--actionpack/lib/action_dispatch/routing/url_for.rb15
1 files changed, 10 insertions, 5 deletions
diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb
index deaf1cdf03..5da41df485 100644
--- a/actionpack/lib/action_dispatch/routing/url_for.rb
+++ b/actionpack/lib/action_dispatch/routing/url_for.rb
@@ -129,16 +129,21 @@ module ActionDispatch
options
when nil, Hash
routes = (options ? options.delete(:routes) : nil) || _routes
- 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)
+ _with_routes(routes) do
+ routes.url_for((options || {}).reverse_merge!(url_options).symbolize_keys)
+ end
else
polymorphic_url(options)
end
end
+
+ def _with_routes(routes)
+ old_routes, @_routes = @_routes, routes
+ yield
+ ensure
+ @_routes = old_routes
+ end
end
end
end