From ed8501ef16fb2f5e4bd4d987740f5e5f62978400 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Tue, 19 Jan 2010 15:23:56 +0530 Subject: Fix DoubleRenderError error message --- actionpack/lib/abstract_controller/rendering.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/abstract_controller/rendering.rb') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index d57136dbb8..0dab4a3cc0 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -42,7 +42,7 @@ module AbstractController # Delegates render_to_body and sticks the result in self.response_body. def render(*args) if response_body - raise AbstractController::DoubleRenderError, "OMG" + raise AbstractController::DoubleRenderError, "Can only render or redirect once per action" end self.response_body = render_to_body(*args) -- cgit v1.2.3 From 8e2fd54b19656a6edbd94f8707927d09e167e7fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 20 Jan 2010 14:21:27 +0100 Subject: Bring normalize behavior to AbstractController::Rendering --- actionpack/lib/abstract_controller/rendering.rb | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/abstract_controller/rendering.rb') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 0dab4a3cc0..644419a585 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" 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) -- cgit v1.2.3 From 6e26be69606c52dbccfad366661b455157c35be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 20 Jan 2010 14:41:23 +0100 Subject: Move ActionController::Translation to AbstractController::Translation. --- actionpack/lib/abstract_controller/rendering.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/abstract_controller/rendering.rb') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 644419a585..826e82c8c6 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -42,7 +42,7 @@ module AbstractController # Delegates render_to_body and sticks the result in self.response_body. def render(*args, &block) if response_body - raise AbstractController::DoubleRenderError, "Can only render or redirect once per action" + raise AbstractController::DoubleRenderError end options = _normalize_options(*args, &block) -- cgit v1.2.3 From d618b7e3dcf2fe6040f025c02bf29691aefc8a71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 22 Jan 2010 17:57:36 +0100 Subject: Ensure strings given to render with slash are rendered relative to the configured _prefix. --- actionpack/lib/abstract_controller/rendering.rb | 37 +++++++++++++++++-------- 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'actionpack/lib/abstract_controller/rendering.rb') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 826e82c8c6..a168b1b4c5 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -98,18 +98,9 @@ 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 + # The prefix used in render "foo" shortcuts. + def _prefix + controller_path end # Return a string representation of a Rack-compatible response body. @@ -126,6 +117,28 @@ module AbstractController private + # Normalize options, by converting render "foo" to render :template => "prefix/foo" + # and render "/foo" to render :file => "/foo". + def _normalize_options(action=nil, options={}) + case action + when Hash + options, action = action, nil + when String, Symbol + action = action.to_s + case action.index("/") + when NilClass + options[:_prefix] = _prefix + options[:_template_name] = action + when 0 + options[:file] = action + else + options[:template] = action + end + end + + options + end + # Take in a set of options and determine the template to render # # ==== Options -- cgit v1.2.3