aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/abstract_controller/rendering.rb
diff options
context:
space:
mode:
authorJosé Valim and Mikel Lindsaar <raasdnil@gmail.com>2010-01-21 11:42:22 +1100
committerJosé Valim and Mikel Lindsaar <raasdnil@gmail.com>2010-01-21 11:42:22 +1100
commitfbdbac2b88218e5e3e6087c67dacf7e755aa4106 (patch)
tree6fdec21b56ab90fc2ec83cbc38033439a9c84e74 /actionpack/lib/abstract_controller/rendering.rb
parentd3da87ce771845f99bbdc04d6d6587b22655b063 (diff)
parentfa9f000246c2f6010f18bf40237d105b782873e2 (diff)
downloadrails-fbdbac2b88218e5e3e6087c67dacf7e755aa4106.tar.gz
rails-fbdbac2b88218e5e3e6087c67dacf7e755aa4106.tar.bz2
rails-fbdbac2b88218e5e3e6087c67dacf7e755aa4106.zip
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'actionpack/lib/abstract_controller/rendering.rb')
-rw-r--r--actionpack/lib/abstract_controller/rendering.rb24
1 files changed, 20 insertions, 4 deletions
diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb
index 0dab4a3cc0..826e82c8c6 100644
--- a/actionpack/lib/abstract_controller/rendering.rb
+++ b/actionpack/lib/abstract_controller/rendering.rb
@@ -40,12 +40,13 @@ module AbstractController
# Mostly abstracts the fact that calling render twice is a DoubleRenderError.
# Delegates render_to_body and sticks the result in self.response_body.
- def render(*args)
+ def render(*args, &block)
if response_body
- raise AbstractController::DoubleRenderError, "Can only render or redirect once per action"
+ raise AbstractController::DoubleRenderError
end
- self.response_body = render_to_body(*args)
+ options = _normalize_options(*args, &block)
+ self.response_body = render_to_body(options)
end
# Raw rendering of a template to a Rack-compatible body.
@@ -69,7 +70,8 @@ module AbstractController
# render_to_body into a String.
#
# :api: plugin
- def render_to_string(options = {})
+ def render_to_string(*args)
+ options = _normalize_options(*args)
AbstractController::Rendering.body_to_s(render_to_body(options))
end
@@ -96,6 +98,20 @@ module AbstractController
_view_paths
end
+ # Normalize options, by converting render "foo" to render :template => "foo"
+ # and render "/foo" to render :file => "/foo".
+ def _normalize_options(action=nil, options={})
+ case action
+ when Hash
+ options, action = action, nil
+ when String
+ key = (action.index("/") == 0 ? :file : :template)
+ options.merge!(key => action)
+ end
+
+ options
+ end
+
# Return a string representation of a Rack-compatible response body.
def self.body_to_s(body)
if body.respond_to?(:to_str)