aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
diff options
context:
space:
mode:
authorYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-04-29 12:19:17 -0700
committerYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-05-01 17:31:01 -0700
commit4f68311685831b940936130203c240fa23525c84 (patch)
tree5fc1192c04bdef4b198a92c511f2a7a5d0e09bc3 /actionpack/lib/action_controller
parent1b459916039259383808625d1758a8bc4a4516d9 (diff)
downloadrails-4f68311685831b940936130203c240fa23525c84.tar.gz
rails-4f68311685831b940936130203c240fa23525c84.tar.bz2
rails-4f68311685831b940936130203c240fa23525c84.zip
Finished implementing render :text in Base2
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r--actionpack/lib/action_controller/abstract/renderer.rb13
-rw-r--r--actionpack/lib/action_controller/new_base/base.rb8
-rw-r--r--actionpack/lib/action_controller/new_base/renderer.rb2
3 files changed, 16 insertions, 7 deletions
diff --git a/actionpack/lib/action_controller/abstract/renderer.rb b/actionpack/lib/action_controller/abstract/renderer.rb
index 37da2398ec..c1f420f7b4 100644
--- a/actionpack/lib/action_controller/abstract/renderer.rb
+++ b/actionpack/lib/action_controller/abstract/renderer.rb
@@ -1,6 +1,15 @@
require "action_controller/abstract/logger"
module AbstractController
+ class AbstractControllerError < StandardError; end
+ class DoubleRenderError < AbstractControllerError
+ DEFAULT_MESSAGE = "Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like \"redirect_to(...) and return\"."
+
+ def initialize(message = nil)
+ super(message || DEFAULT_MESSAGE)
+ end
+ end
+
module Renderer
depends_on AbstractController::Logger
@@ -17,6 +26,10 @@ module AbstractController
end
def render(options = {})
+ unless response_body.nil?
+ raise AbstractController::DoubleRenderError, "OMG"
+ end
+
self.response_body = render_to_body(options)
end
diff --git a/actionpack/lib/action_controller/new_base/base.rb b/actionpack/lib/action_controller/new_base/base.rb
index 6711cd932a..9f7a148b3c 100644
--- a/actionpack/lib/action_controller/new_base/base.rb
+++ b/actionpack/lib/action_controller/new_base/base.rb
@@ -40,23 +40,19 @@ module ActionController
controller.call(env).to_rack
end
- # :api: plugin
- def response_body=(body)
- @_response.body = body
- end
-
# :api: private
def call(env)
@_request = ActionDispatch::Request.new(env)
@_response = ActionDispatch::Response.new
process(@_request.parameters[:action])
+ @_response.body = response_body
@_response.prepare!
self
end
# :api: private
def to_rack
- response.to_a
+ @_response.to_a
end
end
end
diff --git a/actionpack/lib/action_controller/new_base/renderer.rb b/actionpack/lib/action_controller/new_base/renderer.rb
index ed34c46aed..9a965c18e8 100644
--- a/actionpack/lib/action_controller/new_base/renderer.rb
+++ b/actionpack/lib/action_controller/new_base/renderer.rb
@@ -17,7 +17,7 @@ module ActionController
_process_options(options)
- self.response_body = render_to_body(options)
+ super(options)
end
def render_to_body(options)