Skip to content
This repository
Browse code

Always passing a respond block from to responder

We should let the responder to decide what to do with the given
overridden response block, and not short circuit it.

Fixes #5280
  • Loading branch information...
commit 284041cf91a3b2c2d041e71e86fec467080ea9be 1 parent 4c31ba9
Prem Sichanugrist authored March 05, 2012
12  actionpack/lib/action_controller/metal/mime_responds.rb
@@ -235,16 +235,8 @@ def respond_with(*resources, &block)
235 235
 
236 236
       if collector = retrieve_collector_from_mimes(&block)
237 237
         options = resources.size == 1 ? {} : resources.extract_options!
238  
-
239  
-        if defined_response = collector.response
240  
-          if action = options.delete(:action)
241  
-            render :action => action
242  
-          else
243  
-            defined_response.call
244  
-          end
245  
-        else
246  
-          (options.delete(:responder) || self.class.responder).call(self, resources, options)
247  
-        end
  238
+        options[:default_response] = collector.response
  239
+        (options.delete(:responder) || self.class.responder).call(self, resources, options)
248 240
       end
249 241
     end
250 242
 
13  actionpack/lib/action_controller/metal/responder.rb
@@ -130,6 +130,7 @@ def initialize(controller, resources, options={})
130 130
       @resources = resources
131 131
       @options = options
132 132
       @action = options.delete(:action)
  133
+      @default_response = options.delete(:default_response)
133 134
     end
134 135
 
135 136
     delegate :head, :render, :redirect_to,   :to => :controller
@@ -172,7 +173,7 @@ def to_js
172 173
     # responds to :to_format and display it.
173 174
     #
174 175
     def to_format
175  
-      if get? || !has_errors?
  176
+      if get? || !has_errors? || response_overridden?
176 177
         default_render
177 178
       else
178 179
         display_errors
@@ -226,7 +227,11 @@ def resource_location
226 227
     # controller.
227 228
     #
228 229
     def default_render
229  
-      controller.default_render(options)
  230
+      if @default_response
  231
+        @default_response.call(options)
  232
+      else
  233
+        controller.default_render(options)
  234
+      end
230 235
     end
231 236
 
232 237
     # Display is just a shortcut to render a resource with the current format.
@@ -274,5 +279,9 @@ def resource_errors
274 279
     def json_resource_errors
275 280
       {:errors => resource.errors}
276 281
     end
  282
+
  283
+    def response_overridden?
  284
+      @default_response.present?
  285
+    end
277 286
   end
278 287
 end

0 notes on commit 284041c

Please sign in to comment.
Something went wrong with that request. Please try again.