123456789_123456789_123456789_123456789_123456789_

Module: ActionController::ImplicitRender

Do not use. This module is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Defined in: actionpack/lib/action_controller/metal/implicit_render.rb

Overview

Handles implicit rendering for a controller action that does not explicitly respond with render, respond_to, redirect, or head.

For API controllers, the implicit response is always 204 No Content.

For all other controllers, we use these heuristics to decide whether to render a template, raise an error for a missing template, or respond with ‘204 No Content`:

First, if we DO find a template, it’s rendered. Template lookup accounts for the action name, locales, format, variant, template handlers, and more (see render for details).

Second, if we DON’T find a template but the controller action does have templates for other formats, variants, etc., then we trust that you meant to provide a template for this response, too, and we raise UnknownFormat with an explanation.

Third, if we DON’T find a template AND the request is a page load in a web browser (technically, a non-XHR GET request for an HTML response) where you reasonably expect to have rendered a template, then we raise MissingExactTemplate with an explanation.

Finally, if we DON’T find a template AND the request isn’t a browser page load, then we implicitly respond with 204 No Content.

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#interactive_browser_request?Boolean (readonly, private)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/implicit_render.rb', line 63

def interactive_browser_request?
  request.get? && request.format == Mime[:html] && !request.xhr?
end

Instance Method Details

#default_render

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/implicit_render.rb', line 37

def default_render
  if template_exists?(action_name.to_s, _prefixes, variants: request.variant)
    render
  elsif any_templates?(action_name.to_s, _prefixes)
    message = "#{self.class.name}\##{action_name} is missing a template " \
      "for this request format and variant.\n" \
      "\nrequest.formats: #{request.formats.map(&:to_s).inspect}" \
      "\nrequest.variant: #{request.variant.inspect}"

    raise ActionController::UnknownFormat, message
  elsif interactive_browser_request?
    message = "#{self.class.name}\##{action_name} is missing a template for request formats: #{request.formats.map(&:to_s).join(',')}"
    raise ActionController::MissingExactTemplate.new(message, self.class, action_name)
  else
    logger.info "No template found for #{self.class.name}\##{action_name}, rendering head :no_content" if logger
    super
  end
end

#method_for_action(action_name)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/implicit_render.rb', line 56

def method_for_action(action_name)
  super || if template_exists?(action_name.to_s, _prefixes)
             "default_render"
           end
end