instance method use_renderers

Ruby on Rails 5.2.8.1

Since v3.0.20

Available in: v3.0.20 v3.1.12 v3.2.22.5 v4.0.13 v4.1.16 v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

use_renderers(*args)

Adds, by name, a renderer or renderers to the _renderers available to call within controller actions.

It is useful when rendering from an ActionController::Metal controller or otherwise to add an available renderer proc to a specific controller.

Both ActionController::Base and ActionController::API include ActionController::Renderers::All, making all renderers available in the controller. See Renderers::RENDERERS and Renderers.add.

Since ActionController::Metal controllers cannot render, the controller must include AbstractController::Rendering, ActionController::Rendering, and ActionController::Renderers, and have at least one renderer.

Rather than including ActionController::Renderers::All and including all renderers, you may specify which renderers to include by passing the renderer name or names to use_renderers. For example, a controller that includes only the :json renderer (_render_with_renderer_json) might look like:

class MetalRenderingController < ActionController::Metal
  include AbstractController::Rendering
  include ActionController::Rendering
  include ActionController::Renderers

  use_renderers :json

  def show
    render json: record
  end
end

You must specify a use_renderer, else the controller.renderer and controller._renderers will be nil, and the action will fail.

Parameters

args rest
Source
# File actionpack/lib/action_controller/metal/renderers.rb, line 129
      def use_renderers(*args)
        renderers = _renderers + args
        self._renderers = renderers.freeze
      end

Defined in actionpack/lib/action_controller/metal/renderers.rb line 129 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionController::Renderers::ClassMethods

Type at least 2 characters to search.

↑↓ navigate · open · esc close