rails/actionpack/lib/action_controller/metal/url_for.rb
Piotr Sarnacki eedbf87d15 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.
2010-09-03 22:59:05 +02:00

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