Ticket #9953: default_render_patch.diff
| File default_render_patch.diff, 3.8 kB (added by cjheath, 11 months ago) |
|---|
-
actionpack/test/controller/render_test.rb
old new 152 152 end 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 157 174 private … … 413 430 assert_equal 'partial js', @response.body 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 418 440 def etag_for(text) -
actionpack/lib/action_controller/base.rb
old new 70 70 end 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) 76 76 super(message || DEFAULT_MESSAGE) … … 226 226 # 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 232 232 # redirect_to :action => "elsewhere" … … 240 240 # render :action => "overthere" # won't be called unless monkeys is nil 241 241 # end 242 242 # 243 # == Default render 244 # 245 # If you don't call either render or redirect, a default render will occur. 246 # 243 247 class Base 244 248 DEFAULT_RENDER_STATUS_CODE = "200 OK" 245 249 … … 1125 1129 end 1126 1130 end 1127 1131 1132 def default_render 1133 render 1134 end 1135 1128 1136 def perform_action 1129 1137 if self.class.action_methods.include?(action_name) 1130 1138 send(action_name) 1131 render unless performed?1139 default_render unless performed? 1132 1140 elsif respond_to? :method_missing 1133 1141 method_missing action_name 1134 render unless performed?1142 default_render unless performed? 1135 1143 elsif template_exists? && template_public? 1136 render1144 default_render 1137 1145 else 1138 1146 raise UnknownAction, "No action responded to #{action_name}", caller 1139 1147 end