Module: ActionController::UrlFor
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Included In:
Base,
Redirecting,
::ActionView::TestCase::TestController,
Rails::ApplicationController,
Rails::InfoController,
Rails::MailersController,
Rails::WelcomeController
| |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
::ActiveSupport::Concern
|
|
|
Instance Chain:
|
|
| Defined in: | actionpack/lib/action_controller/metal/url_for.rb |
Overview
Includes url_for into the host class. The class has to provide a RouteSet by implementing the _routes method. Otherwise, an exception will be raised.
In addition to ::AbstractController::UrlFor, 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
delegate :env, :request, to: :controller
def initialize(controller)
@controller = controller
@url = root_path # named route from the application.
end
end
Class Method Summary
::ActiveSupport::Concern - Extended
Instance Attribute Summary
Instance Method Summary
::AbstractController::UrlFor - Included
::ActionDispatch::Routing::UrlFor - Included
| #initialize, | |
| #url_for | Generate a url based on the options provided, default_url_options and the routes defined in routes.rb. |
| #url_options | Hook overridden in controller to add request information with |
::ActionDispatch::Routing::PolymorphicRoutes - Included
| #polymorphic_path | Returns the path component of a URL for the given record. |
| #polymorphic_url | Constructs a call to a named RESTful route for the given record and returns the resulting URL string. |
ModelNaming - Included
| #convert_to_model | Converts the given object to an ::ActiveModel compliant one. |
| #model_name_from_record_or_class | |
Instance Method Details
#url_options
[ GitHub ]# File 'actionpack/lib/action_controller/metal/url_for.rb', line 25
def @_url_options ||= { :host => request.host, :port => request.optional_port, :protocol => request.protocol, :_recall => request.path_parameters }.merge!(super).freeze if (same_origin = _routes.equal?(env["action_dispatch.routes".freeze])) || (script_name = env["ROUTES_#{_routes.object_id}_SCRIPT_NAME"]) || (original_script_name = env['ORIGINAL_SCRIPT_NAME'.freeze]) = @_url_options.dup if original_script_name [:original_script_name] = original_script_name else [:script_name] = same_origin ? request.script_name.dup : script_name end .freeze else @_url_options end end