Changeset 8011
- Timestamp:
- 10/25/07 06:38:01 (7 months ago)
- Files:
-
- trunk/actionpack/lib/action_controller/base.rb (modified) (3 diffs)
- trunk/actionpack/test/controller/render_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/lib/action_controller/base.rb
r7999 r8011 71 71 72 72 class DoubleRenderError < ActionControllerError #:nodoc: 73 DEFAULT_MESSAGE = "Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and onlyonce 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\". Finally, note that to cause a before filter to halt execution of the rest of the filter chain, the filter must return false, explicitly, so \"render(...) and return false\"."73 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\". Finally, note that to cause a before filter to halt execution of the rest of the filter chain, the filter must return false, explicitly, so \"render(...) and return false\"." 74 74 75 75 def initialize(message = nil) … … 227 227 # == Calling multiple redirects or renders 228 228 # 229 # An action should conclude with a single render orredirect. Attempting to try to do either again will result in a DoubleRenderError:229 # An action may contain only a single render or a single redirect. Attempting to try to do either again will result in a DoubleRenderError: 230 230 # 231 231 # def do_something … … 1126 1126 end 1127 1127 1128 def default_render #:nodoc: 1129 render 1130 end 1131 1128 1132 def perform_action 1129 1133 if self.class.action_methods.include?(action_name) 1130 1134 send(action_name) 1131 render unless performed?1135 default_render unless performed? 1132 1136 elsif respond_to? :method_missing 1133 1137 method_missing action_name 1134 render unless performed?1138 default_render unless performed? 1135 1139 elsif template_exists? && template_public? 1136 render1140 default_render 1137 1141 else 1138 1142 raise UnknownAction, "No action responded to #{action_name}", caller trunk/actionpack/test/controller/render_test.rb
r7719 r8011 153 153 end 154 154 155 def default_render 156 if @alternate_default_render 157 @alternate_default_render.call 158 else 159 render 160 end 161 end 162 163 def render_alternate_default 164 # For this test, the method "default_render" is overridden: 165 @alternate_default_render = lambda { 166 render :update do |page| 167 page.replace :foo, :partial => 'partial' 168 end 169 } 170 end 171 155 172 def rescue_action(e) raise end 156 173 … … 414 431 end 415 432 433 def test_should_render_with_alternate_default_render 434 xhr :get, :render_alternate_default 435 assert_equal %(Element.replace("foo", "partial html");), @response.body 436 end 437 416 438 protected 417 439