diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2009-04-21 16:03:21 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-04-21 16:03:21 -0700 |
commit | 5afc2abee66cda565f2cb890fe11c3d8e918d882 (patch) | |
tree | c1c2608af14e488435997fb5c5cfa39788fbbe3d /actionpack/lib | |
parent | 696375ac628bd41edf3a8c8c00dde196696f4add (diff) | |
parent | f49e3441280380ec810d54bd5a77a7e699415efb (diff) | |
download | rails-5afc2abee66cda565f2cb890fe11c3d8e918d882.tar.gz rails-5afc2abee66cda565f2cb890fe11c3d8e918d882.tar.bz2 rails-5afc2abee66cda565f2cb890fe11c3d8e918d882.zip |
Merge branch 'master' into cherry
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/abstract/renderer.rb | 12 | ||||
-rw-r--r-- | actionpack/lib/action_controller/base/render.rb | 14 |
2 files changed, 20 insertions, 6 deletions
diff --git a/actionpack/lib/action_controller/abstract/renderer.rb b/actionpack/lib/action_controller/abstract/renderer.rb index eb248652a8..2a68f048bd 100644 --- a/actionpack/lib/action_controller/abstract/renderer.rb +++ b/actionpack/lib/action_controller/abstract/renderer.rb @@ -20,7 +20,7 @@ module AbstractController self.response_body = render_to_body(options) end - # Raw rendering of a template. + # Raw rendering of a template to a Rack-compatible body. # ==== # @option _prefix<String> The template's path prefix # @option _layout<String> The relative path to the layout template to use @@ -33,6 +33,16 @@ module AbstractController _render_template(template, options) end + # Raw rendering of a template to a string. + # ==== + # @option _prefix<String> The template's path prefix + # @option _layout<String> The relative path to the layout template to use + # + # :api: plugin + def render_to_string(options = {}) + Rack::Utils.body_to_s(render_to_body(options)).to_ary.join + end + def _render_template(template, options) _action_view._render_template_with_layout(template) end diff --git a/actionpack/lib/action_controller/base/render.rb b/actionpack/lib/action_controller/base/render.rb index 0d24f18633..604dd31930 100644 --- a/actionpack/lib/action_controller/base/render.rb +++ b/actionpack/lib/action_controller/base/render.rb @@ -306,9 +306,9 @@ module ActionController (name.is_a?(String) ? name.sub(/^#{controller_path}\//, '') : name).to_s end - # Renders according to the same rules as <tt>render</tt>, but returns the result in a string instead - # of sending it as the response body to the browser. - def render_to_string(options = nil, &block) #:doc: + # Same rules as <tt>render</tt>, but returns a Rack-compatible body + # instead of sending the response. + def render_to_body(options = nil, &block) #:doc: render(options, &block) response.body ensure @@ -316,7 +316,11 @@ module ActionController erase_render_results reset_variables_added_to_assigns end - + + def render_to_string(options = {}) + Rack::Utils.body_to_s(render_to_body(options)).to_ary.join + end + # Clears the rendered results, allowing for another render to be performed. def erase_render_results #:nodoc: response.body = [] @@ -387,4 +391,4 @@ module ActionController render_for_parts(parts, layout, options) end end -end
\ No newline at end of file +end |