123456789_123456789_123456789_123456789_123456789_

Module: ActionController::Renderers::ClassMethods

Relationships & Source Files
Defined in: actionpack/lib/action_controller/metal/renderers.rb

Instance Method Summary

Instance Method Details

#use_renderer(*args)

Alias for #use_renderers.

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/renderers.rb', line 131

alias use_renderer use_renderers

#use_renderers(*args) Also known as: #use_renderer

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 All, making all renderers available in the controller. See RENDERERS and ActionController::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 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.

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/renderers.rb', line 127

def use_renderers(*args)
  renderers = _renderers + args
  self._renderers = renderers.freeze
end