mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
ask the routes objects for its Rack env key
this centralizes the logic for determining the script name key and drops object allocations when calling `engine_script_name` (which is called on each `url_for`).
This commit is contained in:
parent
a8a361cf80
commit
37654d12ae
3 changed files with 4 additions and 2 deletions
|
@ -114,7 +114,7 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
def engine_script_name(_routes) # :nodoc:
|
||||
env["ROUTES_#{_routes.object_id}_SCRIPT_NAME"]
|
||||
env[_routes.env_key]
|
||||
end
|
||||
|
||||
def request_method=(request_method) #:nodoc:
|
||||
|
|
|
@ -308,6 +308,7 @@ module ActionDispatch
|
|||
attr_accessor :formatter, :set, :named_routes, :default_scope, :router
|
||||
attr_accessor :disable_clear_and_finalize, :resources_path_names
|
||||
attr_accessor :default_url_options, :request_class
|
||||
attr_reader :env_key
|
||||
|
||||
alias :routes :set
|
||||
|
||||
|
@ -325,6 +326,7 @@ module ActionDispatch
|
|||
@prepend = []
|
||||
@disable_clear_and_finalize = false
|
||||
@finalized = false
|
||||
@env_key = "ROUTES_#{object_id}_SCRIPT_NAME".freeze
|
||||
|
||||
@set = Journey::Routes.new
|
||||
@router = Journey::Router.new @set
|
||||
|
|
|
@ -513,7 +513,7 @@ module Rails
|
|||
def call(env)
|
||||
env.merge!(env_config)
|
||||
if env['SCRIPT_NAME']
|
||||
env["ROUTES_#{routes.object_id}_SCRIPT_NAME"] = env['SCRIPT_NAME'].dup
|
||||
env[routes.env_key] = env['SCRIPT_NAME'].dup
|
||||
end
|
||||
app.call(env)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue