Permalink
Browse files

Add #rendered_format method to controllers

  • Loading branch information...
lukaszx0 committed Aug 2, 2013
1 parent 1b1c235 commit 7d810049fe8905e3e96d0b2e989f562bb961e59e
@@ -47,6 +47,11 @@ def render_to_body(options = {})
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
@@ -10,17 +10,17 @@ def process_action(*) #:nodoc:
# 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
@@ -107,6 +107,10 @@ def _render_template(options) #:nodoc:
view_renderer.render(view_context, options)
end
+ def rendered_format
+ Mime[lookup_context.rendered_format]
+ end
+
def default_protected_instance_vars
super.concat([:@_view_context_class, :@_view_renderer, :@_lookup_context])
end

0 comments on commit 7d81004

Please sign in to comment.