Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@sikachu sikachu authored
View
12 actionpack/lib/action_controller/metal/mime_responds.rb
@@ -235,16 +235,8 @@ def respond_with(*resources, &block)
if collector = retrieve_collector_from_mimes(&block)
options = resources.size == 1 ? {} : resources.extract_options!
-
- if defined_response = collector.response
- if action = options.delete(:action)
- render :action => action
- else
- defined_response.call
- end
- else
- (options.delete(:responder) || self.class.responder).call(self, resources, options)
- end
+ options[:default_response] = collector.response
+ (options.delete(:responder) || self.class.responder).call(self, resources, options)
end
end
View
13 actionpack/lib/action_controller/metal/responder.rb
@@ -130,6 +130,7 @@ def initialize(controller, resources, options={})
@resources = resources
@options = options
@action = options.delete(:action)
+ @default_response = options.delete(:default_response)
end
delegate :head, :render, :redirect_to, :to => :controller
@@ -172,7 +173,7 @@ def to_js
# responds to :to_format and display it.
#
def to_format
- if get? || !has_errors?
+ if get? || !has_errors? || response_overridden?
default_render
else
display_errors
@@ -226,7 +227,11 @@ def resource_location
# controller.
#
def default_render
- controller.default_render(options)
+ if @default_response
+ @default_response.call(options)
+ else
+ controller.default_render(options)
+ end
end
# Display is just a shortcut to render a resource with the current format.
@@ -274,5 +279,9 @@ def resource_errors
def json_resource_errors
{:errors => resource.errors}
end
+
+ def response_overridden?
+ @default_response.present?
+ end
end
end

0 comments on commit 284041c

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