From 103e18c87d50a53cd0a33b4e03f2c8a8eff19ece Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Fri, 31 Jan 2014 15:37:58 -0500 Subject: Introduce `render :body` for render raw content This is an option for sending a raw content back to browser. Note that this rendering option will unset the default content type and does not include "Content-Type" header back in the response. You should only use this option if you are expecting the "Content-Type" header to not be set. More information on "Content-Type" header can be found on RFC 2616, section 7.2.1. Please see #12374 for more detail. --- actionpack/lib/action_controller/metal/rendering.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb index 5c48b4ab98..c9ae1ab388 100644 --- a/actionpack/lib/action_controller/metal/rendering.rb +++ b/actionpack/lib/action_controller/metal/rendering.rb @@ -27,14 +27,19 @@ module ActionController end def render_to_body(options = {}) - super || options[:text].presence || ' ' + super || options[:body].presence || options[:text].presence || ' ' end private - def _process_format(format) + def _process_format(format, options = {}) super self.content_type ||= format.to_s + + if options[:body].present? + self.content_type = "none" + self.headers.delete "Content-Type" + end end # Normalize arguments by catching blocks and setting them on :update. @@ -46,12 +51,16 @@ module ActionController # Normalize both text and status options. def _normalize_options(options) #:nodoc: + if options.key?(:body) && options[:body].respond_to?(:to_text) + options[:body] = options[:body].to_text + end + if options.key?(:text) && options[:text].respond_to?(:to_text) options[:text] = options[:text].to_text end - if options.delete(:nothing) || (options.key?(:text) && options[:text].nil?) - options[:text] = " " + if options.delete(:nothing) || (options.key?(:body) && options[:body].nil?) || (options.key?(:text) && options[:text].nil?) + options[:body] = " " end if options[:status] -- cgit v1.2.3