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
|
2015-03-06 06:48:46 -05:00
|
|
|
# to implement +env+ which needs to be Rack-compatible and +request+
|
2015-04-05 09:55:18 -04:00
|
|
|
# which is either an instance of +ActionDispatch::Request+ or an object
|
|
|
|
# that responds to the +host+, +optional_port+, +protocol+ and
|
|
|
|
# +symbolized_path_parameter+ methods.
|
2012-03-06 14:34:14 -05:00
|
|
|
#
|
|
|
|
# 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,
|
2014-05-22 18:12:03 -04:00
|
|
|
:_recall => request.path_parameters
|
2014-07-31 08:43:02 -04:00
|
|
|
}.merge!(super).freeze
|
2010-09-27 15:14:18 -04:00
|
|
|
|
2014-12-30 17:47:51 -05:00
|
|
|
if (same_origin = _routes.equal?(request.routes)) ||
|
2014-12-30 18:18:20 -05:00
|
|
|
(script_name = request.engine_script_name(_routes)) ||
|
2014-12-30 17:47:51 -05:00
|
|
|
(original_script_name = request.original_script_name)
|
2013-05-03 10:42:31 -04:00
|
|
|
|
2014-07-31 08:47:46 -04:00
|
|
|
options = @_url_options.dup
|
|
|
|
if original_script_name
|
|
|
|
options[:original_script_name] = original_script_name
|
|
|
|
else
|
2015-07-24 23:32:01 -04:00
|
|
|
if same_origin
|
|
|
|
options[:script_name] = request.script_name.empty? ? "".freeze : request.script_name.dup
|
|
|
|
else
|
|
|
|
options[:script_name] = script_name
|
|
|
|
end
|
2010-09-27 09:11:19 -04:00
|
|
|
end
|
2014-07-31 08:47:46 -04:00
|
|
|
options.freeze
|
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
|