The render
method you call in your action is defined in ActionController::Base
.
def render(action = nil, options = {}, &blk)
options = _normalize_options(action, options, &blk)
super(options)
end
This method passes the call to super
which calls the render
method defined in ActionController::Rendering
.
def render(options)
super
self.content_type ||= options[:_template].mime_type.to_s
response_body
end
ActionController::Rendering
is effectively a Module, mixed into the ActionController::Base class at the beginning of the base.rb
file.
include ActionController::Redirecting
include ActionController::Rendering # <--
include ActionController::Renderers::All
In turns, ActionController::Rendering
includes AbstractController::Rendering
as you can see in the ActionController::Rendering
module definition.
module ActionController
module Rendering
extend ActiveSupport::Concern
included do
include AbstractController::Rendering
include AbstractController::LocalizedCache
end
AbstractController::Rendering
provides a render
method which is the final method invoked in the render chain.
# Mostly abstracts the fact that calling render twice is a DoubleRenderError.
# Delegates render_to_body and sticks the result in self.response_body.
def render(*args)
if response_body
raise AbstractController::DoubleRenderError, "Can only render or redirect once per action"
end
self.response_body = render_to_body(*args)
end
The full chain is
AbstractController::Base#render
--> super()
--> ActionController::Rendering#render
--> super()
--> AbstractController::Rendering#render
--> render_to_body