From 7d810049fe8905e3e96d0b2e989f562bb961e59e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Strza=C5=82kowski?= Date: Fri, 2 Aug 2013 02:27:28 +0200 Subject: Add #rendered_format method to controllers --- actionpack/lib/abstract_controller/rendering.rb | 5 +++++ actionpack/lib/action_controller/metal/rendering.rb | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 93ded404d6..5a5c47eb3b 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -47,6 +47,11 @@ module AbstractController def render(*args, &block) end + # Return Content-Type of rendered content + # :api: public + def rendered_format + end + # This method should return a hash with assigns. # You can overwrite this configuration per controller. # :api: public diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb index f0e8945f11..abcc9d4acf 100644 --- a/actionpack/lib/action_controller/metal/rendering.rb +++ b/actionpack/lib/action_controller/metal/rendering.rb @@ -10,17 +10,17 @@ module ActionController # Check for double render errors and set the content_type after rendering. def render(*args) #:nodoc: - raise ::AbstractController::DoubleRenderError if response_body + raise ::AbstractController::DoubleRenderError if self.response_body super - self.content_type ||= Mime[lookup_context.rendered_format].to_s - response_body + self.content_type ||= rendered_format.to_s + self.response_body end # Overwrite render_to_string because body can now be set to a rack body. def render_to_string(*) if self.response_body = super string = "" - response_body.each { |r| string << r } + self.response_body.each { |r| string << r } string end ensure -- cgit v1.2.3