diff options
author | Łukasz Strzałkowski <lukasz.strzalkowski@gmail.com> | 2013-08-02 02:27:28 +0200 |
---|---|---|
committer | Łukasz Strzałkowski <lukasz.strzalkowski@gmail.com> | 2013-08-25 11:39:13 +0200 |
commit | 7d810049fe8905e3e96d0b2e989f562bb961e59e (patch) | |
tree | f835d0511c3c1f620307a5779e621e5a9fff988d | |
parent | 1b1c23599bf0b4c16fec260ed993b27a8cc92724 (diff) | |
download | rails-7d810049fe8905e3e96d0b2e989f562bb961e59e.tar.gz rails-7d810049fe8905e3e96d0b2e989f562bb961e59e.tar.bz2 rails-7d810049fe8905e3e96d0b2e989f562bb961e59e.zip |
Add #rendered_format method to controllers
-rw-r--r-- | actionpack/lib/abstract_controller/rendering.rb | 5 | ||||
-rw-r--r-- | actionpack/lib/action_controller/metal/rendering.rb | 8 | ||||
-rw-r--r-- | actionview/lib/action_view/rendering.rb | 4 |
3 files changed, 13 insertions, 4 deletions
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 diff --git a/actionview/lib/action_view/rendering.rb b/actionview/lib/action_view/rendering.rb index fa1c984726..88a3de4a45 100644 --- a/actionview/lib/action_view/rendering.rb +++ b/actionview/lib/action_view/rendering.rb @@ -107,6 +107,10 @@ module ActionView 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 |