From f49e3441280380ec810d54bd5a77a7e699415efb Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 21 Apr 2009 16:02:30 -0700 Subject: Reinstate Base#render_to_string. Introduce AbstractController#render_to_string which stringifies render_to_body. --- actionpack/lib/action_controller/base/render.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'actionpack/lib/action_controller/base/render.rb') 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 render, 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 render, 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 -- cgit v1.2.3