From 8cd9f6d205e5db5331dd5b01be35b537da17cdee Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Fri, 7 Feb 2014 13:45:57 -0500 Subject: 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. --- actionpack/lib/action_controller/metal/rendering.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') 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 -- cgit v1.2.3