eedbf87d15
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.
38 lines
1.0 KiB
Ruby
38 lines
1.0 KiB
Ruby
module ActionController
|
|
module UrlFor
|
|
extend ActiveSupport::Concern
|
|
|
|
include ActionDispatch::Routing::UrlFor
|
|
|
|
def url_options
|
|
options = {}
|
|
if respond_to?(:env) && env
|
|
if _routes.equal?(env["action_dispatch.routes"])
|
|
options[:skip_prefix] = true
|
|
elsif env["action_dispatch.routes"]
|
|
options[:script_name] = _routes.default_url_options[:script_name]
|
|
end
|
|
end
|
|
|
|
super.merge(options).reverse_merge(
|
|
:host => request.host_with_port,
|
|
:protocol => request.protocol,
|
|
:_path_segments => request.symbolized_path_parameters
|
|
).reverse_merge(:script_name => request.script_name)
|
|
end
|
|
|
|
def _routes
|
|
raise "In order to use #url_for, you must include routing helpers explicitly. " \
|
|
"For instance, `include Rails.application.routes.url_helpers"
|
|
end
|
|
|
|
module ClassMethods
|
|
def action_methods
|
|
@action_methods ||= begin
|
|
super - _routes.named_routes.helper_names
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|