2010-02-25 18:05:10 -05:00
|
|
|
module ActionController
|
2012-03-06 14:34:14 -05:00
|
|
|
# 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
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# class RootUrl
|
|
|
|
# include ActionController::UrlFor
|
|
|
|
# include Rails.application.routes.url_helpers
|
|
|
|
#
|
2012-10-27 16:05:27 -04:00
|
|
|
# delegate :env, :request, to: :controller
|
2012-03-06 14:34:14 -05:00
|
|
|
#
|
|
|
|
# def initialize(controller)
|
|
|
|
# @controller = controller
|
|
|
|
# @url = root_path # named route from the application.
|
|
|
|
# end
|
|
|
|
# end
|
2010-02-25 18:05:10 -05:00
|
|
|
module UrlFor
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2010-08-03 13:36:53 -04:00
|
|
|
include AbstractController::UrlFor
|
2010-02-25 18:05:10 -05:00
|
|
|
|
2010-02-26 18:20:41 -05:00
|
|
|
def url_options
|
2014-05-21 18:51:28 -04:00
|
|
|
@_url_options ||= {
|
2012-03-02 12:47:15 -05:00
|
|
|
:host => request.host,
|
|
|
|
:port => request.optional_port,
|
|
|
|
:protocol => request.protocol,
|
2012-08-04 07:55:00 -04:00
|
|
|
:_recall => request.symbolized_path_parameters
|
2014-05-21 18:51:28 -04:00
|
|
|
}.merge(super).freeze
|
2010-09-27 15:14:18 -04:00
|
|
|
|
2014-04-30 17:24:14 -04:00
|
|
|
if (same_origin = _routes.equal?(env["action_dispatch.routes".freeze])) ||
|
2012-08-10 17:27:51 -04:00
|
|
|
(script_name = env["ROUTES_#{_routes.object_id}_SCRIPT_NAME"]) ||
|
2014-04-30 17:48:37 -04:00
|
|
|
(original_script_name = env['ORIGINAL_SCRIPT_NAME'.freeze])
|
2013-05-03 10:42:31 -04:00
|
|
|
|
2012-03-02 12:47:15 -05:00
|
|
|
@_url_options.dup.tap do |options|
|
2012-08-10 17:27:51 -04:00
|
|
|
if original_script_name
|
|
|
|
options[:original_script_name] = original_script_name
|
|
|
|
else
|
|
|
|
options[:script_name] = same_origin ? request.script_name.dup : script_name
|
|
|
|
end
|
2012-03-02 12:47:15 -05:00
|
|
|
options.freeze
|
2010-09-27 09:11:19 -04:00
|
|
|
end
|
2012-03-02 12:47:15 -05:00
|
|
|
else
|
|
|
|
@_url_options
|
2010-09-27 09:11:19 -04:00
|
|
|
end
|
2010-02-25 18:05:10 -05:00
|
|
|
end
|
|
|
|
end
|
2010-07-01 18:29:20 -04:00
|
|
|
end
|