diff options
author | José Valim <jose.valim@gmail.com> | 2012-03-02 01:32:08 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-03-02 01:59:03 +0100 |
commit | d7014bc7eaa62c36f045a503cdad64e4ebbc2687 (patch) | |
tree | 4e3f61401118514fd4f4eb3de2721bada019f44c /actionpack/lib/action_controller | |
parent | fcef72890b7f8b974ee490268a48e147bd621253 (diff) | |
download | rails-d7014bc7eaa62c36f045a503cdad64e4ebbc2687.tar.gz rails-d7014bc7eaa62c36f045a503cdad64e4ebbc2687.tar.bz2 rails-d7014bc7eaa62c36f045a503cdad64e4ebbc2687.zip |
Optimize path helpers.
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/metal/url_for.rb | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/actionpack/lib/action_controller/metal/url_for.rb b/actionpack/lib/action_controller/metal/url_for.rb index 0b40b1fc4c..4504d9cd10 100644 --- a/actionpack/lib/action_controller/metal/url_for.rb +++ b/actionpack/lib/action_controller/metal/url_for.rb @@ -1,7 +1,7 @@ -# Includes +url_for+ into the host class. The class has to provide a +RouteSet+ by implementing +# Includes +url_for+ into the host class. The class has to provide a +RouteSet+ by implementing # the <tt>_routes</tt> method. Otherwise, an exception will be raised. # -# In addition to <tt>AbstractController::UrlFor</tt>, this module accesses the HTTP layer to define +# In addition to <tt>AbstractController::UrlFor</tt>, this module accesses the HTTP layer to define # url options like the +host+. In order to do so, this module requires the host class # to implement +env+ and +request+, which need to be a Rack-compatible. # @@ -18,7 +18,7 @@ # @url = root_path # named route from the application. # end # end -# +# module ActionController module UrlFor extend ActiveSupport::Concern @@ -26,22 +26,20 @@ module ActionController include AbstractController::UrlFor def url_options - @_url_options ||= super.reverse_merge( - :host => request.host, - :port => request.optional_port, - :protocol => request.protocol, - :_path_segments => request.symbolized_path_parameters - ).freeze + @_url_options ||= begin + hash = super.reverse_merge( + :host => request.host, + :port => request.optional_port, + :protocol => request.protocol, + :_path_segments => request.symbolized_path_parameters + ) - if _routes.equal?(env["action_dispatch.routes"]) - @_url_options.dup.tap do |options| - options[:script_name] = request.script_name.dup - options.freeze + if _routes.equal?(env["action_dispatch.routes"]) + hash[:script_name] = request.script_name.dup end - else - @_url_options + + hash.freeze end end - end end |