diff options
author | Prem Sichanugrist <s@sikac.hu> | 2014-02-07 13:45:57 -0500 |
---|---|---|
committer | Prem Sichanugrist <s@sikac.hu> | 2014-02-18 12:08:36 -0500 |
commit | 8cd9f6d205e5db5331dd5b01be35b537da17cdee (patch) | |
tree | 63de043c2a65cddf20105e608ea60af1a1e65e20 /actionpack/lib/action_controller/metal | |
parent | 9e9cc660773d331b04a829b4a727af70b3e23c16 (diff) | |
download | rails-8cd9f6d205e5db5331dd5b01be35b537da17cdee.tar.gz rails-8cd9f6d205e5db5331dd5b01be35b537da17cdee.tar.bz2 rails-8cd9f6d205e5db5331dd5b01be35b537da17cdee.zip |
Introduce `render :plain` for render plain text
This is as an option to render content with a content type of
`text/plain`. This is the preferred option if you are planning to render
a plain text content.
Please see #12374 for more detail.
Diffstat (limited to 'actionpack/lib/action_controller/metal')
-rw-r--r-- | actionpack/lib/action_controller/metal/rendering.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb index c9ae1ab388..3133334369 100644 --- a/actionpack/lib/action_controller/metal/rendering.rb +++ b/actionpack/lib/action_controller/metal/rendering.rb @@ -27,7 +27,7 @@ module ActionController end def render_to_body(options = {}) - super || options[:body].presence || options[:text].presence || ' ' + super || options[:body].presence || options[:text].presence || options[:plain].presence || ' ' end private @@ -40,6 +40,10 @@ module ActionController self.content_type = "none" self.headers.delete "Content-Type" end + + if options[:plain].present? + self.content_type = Mime::TEXT + end end # Normalize arguments by catching blocks and setting them on :update. @@ -59,7 +63,11 @@ module ActionController options[:text] = options[:text].to_text end - if options.delete(:nothing) || (options.key?(:body) && options[:body].nil?) || (options.key?(:text) && options[:text].nil?) + if options.key?(:plain) && options[:plain].respond_to?(:to_text) + options[:plain] = options[:plain].to_text + end + + if options.delete(:nothing) || (options.key?(:body) && options[:body].nil?) || (options.key?(:text) && options[:text].nil?) || (options.key?(:plain) && options[:plain].nil?) options[:body] = " " end |