Get rid of :skip_prefix options in routes
This commit is contained in:
parent
b1e5e233fa
commit
8a077089d9
@ -5,20 +5,16 @@ module UrlFor
|
|||||||
include ActionDispatch::Routing::UrlFor
|
include ActionDispatch::Routing::UrlFor
|
||||||
|
|
||||||
def url_options
|
def url_options
|
||||||
options = {}
|
options = {}
|
||||||
if respond_to?(:env) && env
|
if respond_to?(:env) && env && _routes.equal?(env["action_dispatch.routes"])
|
||||||
if _routes.equal?(env["action_dispatch.routes"])
|
options[:script_name] = request.script_name
|
||||||
options[:skip_prefix] = true
|
|
||||||
elsif env["action_dispatch.routes"]
|
|
||||||
options[:script_name] = _routes.default_url_options[:script_name]
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
super.merge(options).reverse_merge(
|
super.merge(options).reverse_merge(
|
||||||
:host => request.host_with_port,
|
:host => request.host_with_port,
|
||||||
:protocol => request.protocol,
|
:protocol => request.protocol,
|
||||||
:_path_segments => request.symbolized_path_parameters
|
:_path_segments => request.symbolized_path_parameters
|
||||||
).reverse_merge(:script_name => request.script_name)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def _routes
|
def _routes
|
||||||
|
@ -452,7 +452,7 @@ def generate(options, recall = {}, extras = false)
|
|||||||
Generator.new(options, recall, self, extras).generate
|
Generator.new(options, recall, self, extras).generate
|
||||||
end
|
end
|
||||||
|
|
||||||
RESERVED_OPTIONS = [:anchor, :params, :only_path, :host, :protocol, :port, :trailing_slash, :script_name, :skip_prefix, :routes]
|
RESERVED_OPTIONS = [:anchor, :params, :only_path, :host, :protocol, :port, :trailing_slash, :script_name, :routes]
|
||||||
|
|
||||||
def _generate_prefix(options = {})
|
def _generate_prefix(options = {})
|
||||||
nil
|
nil
|
||||||
@ -478,15 +478,12 @@ def url_for(options)
|
|||||||
rewritten_url << ":#{options.delete(:port)}" if options.key?(:port)
|
rewritten_url << ":#{options.delete(:port)}" if options.key?(:port)
|
||||||
end
|
end
|
||||||
|
|
||||||
path = [options.delete(:script_name)]
|
script_name = options.delete(:script_name)
|
||||||
if !options.delete(:skip_prefix)
|
path = (script_name.blank? ? _generate_prefix(options) : script_name).to_s
|
||||||
path << _generate_prefix(options)
|
|
||||||
end
|
|
||||||
|
|
||||||
path_options = options.except(*RESERVED_OPTIONS)
|
path_options = options.except(*RESERVED_OPTIONS)
|
||||||
path_options = yield(path_options) if block_given?
|
path_options = yield(path_options) if block_given?
|
||||||
path << generate(path_options, path_segments || {})
|
path << generate(path_options, path_segments || {})
|
||||||
path = path.compact.join ''
|
|
||||||
|
|
||||||
# ROUTES TODO: This can be called directly, so script_name should probably be set in the routes
|
# ROUTES TODO: This can be called directly, so script_name should probably be set in the routes
|
||||||
rewritten_url << (options[:trailing_slash] ? path.sub(/\?|\z/) { "/" + $& } : path)
|
rewritten_url << (options[:trailing_slash] ? path.sub(/\?|\z/) { "/" + $& } : path)
|
||||||
|
@ -31,7 +31,7 @@ def app
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "the request's SCRIPT_NAME takes precedence over the routes'" do
|
test "the request's SCRIPT_NAME takes precedence over the routes'" do
|
||||||
get "/foo", {}, 'SCRIPT_NAME' => "/new"
|
get "/foo", {}, 'SCRIPT_NAME' => "/new", 'action_dispatch.routes' => Routes
|
||||||
assert_equal "/new/foo", response.body
|
assert_equal "/new/foo", response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user