diff options
author | Prem Sichanugrist <s@sikac.hu> | 2014-01-31 15:37:58 -0500 |
---|---|---|
committer | Prem Sichanugrist <s@sikac.hu> | 2014-02-18 12:08:36 -0500 |
commit | 103e18c87d50a53cd0a33b4e03f2c8a8eff19ece (patch) | |
tree | 07f0d46e80ea3dd978e4a6ca3e533087d76ca7f8 /actionpack/lib/action_controller/metal/rendering.rb | |
parent | 6c496a6d2a21fb8f6f5fb4a97acf1f2de828d1d5 (diff) | |
download | rails-103e18c87d50a53cd0a33b4e03f2c8a8eff19ece.tar.gz rails-103e18c87d50a53cd0a33b4e03f2c8a8eff19ece.tar.bz2 rails-103e18c87d50a53cd0a33b4e03f2c8a8eff19ece.zip |
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.
Diffstat (limited to 'actionpack/lib/action_controller/metal/rendering.rb')
-rw-r--r-- | actionpack/lib/action_controller/metal/rendering.rb | 17 |
1 files changed, 13 insertions, 4 deletions
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] |