Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

render_to_string should have the identical signature as render

  • Loading branch information...
commit 209fb5190b1415633fcd42f7617ff5001669dd27 1 parent 723e91e
@wycats wycats authored
View
17 actionpack/lib/abstract_controller/rendering.rb
@@ -89,9 +89,16 @@ def view_context
# Normalize arguments, options and then delegates render_to_body and
# sticks the result in self.response_body.
def render(*args, &block)
+ self.response_body = render_to_string(*args, &block)
+ end
+
+ # Raw rendering of a template to a string. Just convert the results of
+ # render_to_body into a String.
+ # :api: plugin
+ def render_to_string(*args, &block)
options = _normalize_args(*args, &block)
_normalize_options(options)
- self.response_body = render_to_body(options)
+ render_to_body(options)
end
# Raw rendering of a template to a Rack-compatible body.
@@ -101,14 +108,6 @@ def render_to_body(options = {})
_render_template(options)
end
- # Raw rendering of a template to a string. Just convert the results of
- # render_to_body into a String.
- # :api: plugin
- def render_to_string(options={})
- _normalize_options(options)
- render_to_body(options)
- end
-
# Find and renders a template based on the options given.
# :api: private
def _render_template(options) #:nodoc:
View
10 actionpack/test/abstract/abstract_controller_test.rb
@@ -49,6 +49,11 @@ def index
render "index.erb"
end
+
+ def index_to_string
+ self.response_body = render_to_string "index.erb"
+ end
+
def action_with_ivars
@my_ivar = "Hello"
render "action_with_ivars.erb"
@@ -77,6 +82,11 @@ def setup
assert_equal "Hello from index.erb", @controller.response_body
end
+ test "render_to_string works with a String as an argument" do
+ @controller.process(:index_to_string)
+ assert_equal "Hello from index.erb", @controller.response_body
+ end
+
test "rendering passes ivars to the view" do
@controller.process(:action_with_ivars)
assert_equal "Hello from index_with_ivars.erb", @controller.response_body

1 comment on commit 209fb51

@Empact

Hell Yes.

Please sign in to comment.
Something went wrong with that request. Please try again.