diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2015-12-31 20:17:00 -0200 |
---|---|---|
committer | Rafael França <rafaelmfranca@gmail.com> | 2015-12-31 20:17:00 -0200 |
commit | 8167fa4562841f4ae7ce307ce0c91a448a695ad9 (patch) | |
tree | 6e1a4db616e1b7c322075dac1b610525c207eef7 /actionpack/lib | |
parent | 15299f3a5c0e068b4945bdb8199755100dc91e13 (diff) | |
parent | 1c361ea356aba4936347c83213b2adf50e2f4af2 (diff) | |
download | rails-8167fa4562841f4ae7ce307ce0c91a448a695ad9.tar.gz rails-8167fa4562841f4ae7ce307ce0c91a448a695ad9.tar.bz2 rails-8167fa4562841f4ae7ce307ce0c91a448a695ad9.zip |
Merge pull request #22519 from bf4/test_use_renderers
Add tests for ActionController::Renderers::use_renderers
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/metal/renderers.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/metal/renderers.rb b/actionpack/lib/action_controller/metal/renderers.rb index 22e0bb5955..1f77f9ecaa 100644 --- a/actionpack/lib/action_controller/metal/renderers.rb +++ b/actionpack/lib/action_controller/metal/renderers.rb @@ -26,6 +26,40 @@ module ActionController end module ClassMethods + + # Adds, by name, a renderer or renderers to the +_renderers+ available + # to call within controller actions. + # + # It is useful when rendering from an <tt>ActionController::Metal</tt> controller or + # otherwise to add an available renderer proc to a specific controller. + # + # Both <tt>ActionController::Base</tt> and <tt>ActionController::API</tt> + # include <tt>ActionController::Renderers::All</tt>, making all renderers + # avaialable in the controller. See <tt>Renderers::RENDERERS</tt> and <tt>Renderers.add</tt>. + # + # Since <tt>ActionController::Metal</tt> controllers cannot render, the controller + # must include <tt>AbstractController::Rendering</tt>, <tt>ActionController::Rendering</tt>, + # and <tt>ActionController::Renderers</tt>, and have at lest one renderer. + # + # Rather than including <tt>ActionController::Renderers::All</tt> 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 <tt>:json</tt> 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 <tt>nil</tt>, and the action will fail. def use_renderers(*args) renderers = _renderers + args self._renderers = renderers.freeze |