aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/metal/mime_responds.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-08-29 16:18:37 +0200
committerYehuda Katz <wycats@gmail.com>2009-08-29 11:01:00 -0500
commit684a6b3c71110b018199bf412e485189343e1f6d (patch)
tree3a004aedfa41b4dbe3d80f92c5d6be7348785837 /actionpack/lib/action_controller/metal/mime_responds.rb
parentdbf20c2dbb5d1f2640517c468aa7c269d93414b9 (diff)
downloadrails-684a6b3c71110b018199bf412e485189343e1f6d.tar.gz
rails-684a6b3c71110b018199bf412e485189343e1f6d.tar.bz2
rails-684a6b3c71110b018199bf412e485189343e1f6d.zip
Attempt to render the template inside the responder, so it can be used for caching and pagination.
Signed-off-by: Yehuda Katz <wycats@gmail.com>
Diffstat (limited to 'actionpack/lib/action_controller/metal/mime_responds.rb')
-rw-r--r--actionpack/lib/action_controller/metal/mime_responds.rb49
1 files changed, 28 insertions, 21 deletions
diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb
index 950105e63f..6a32aeae24 100644
--- a/actionpack/lib/action_controller/metal/mime_responds.rb
+++ b/actionpack/lib/action_controller/metal/mime_responds.rb
@@ -178,23 +178,7 @@ module ActionController #:nodoc:
#
def respond_to(*mimes, &block)
raise ArgumentError, "respond_to takes either types or a block, never both" if mimes.any? && block_given?
-
- collector = Collector.new
- mimes = collect_mimes_from_class_level if mimes.empty?
- mimes.each { |mime| collector.send(mime) }
- block.call(collector) if block_given?
-
- if format = request.negotiate_mime(collector.order)
- self.formats = [format.to_sym]
-
- if response = collector.response_for(format)
- response.call
- else
- default_render
- end
- else
- head :not_acceptable
- end
+ collect_mimes_for_render(mimes, block){ default_render }
end
# respond_with wraps a resource around a responder for default representation.
@@ -227,10 +211,10 @@ module ActionController #:nodoc:
# a proc to it.
#
def respond_with(*resources, &block)
- respond_to(&block)
- rescue ActionView::MissingTemplate
- options = resources.extract_options!
- (options.delete(:responder) || responder).call(self, resources, options)
+ collect_mimes_for_render([], block) do
+ options = resources.extract_options!
+ (options.delete(:responder) || responder).call(self, resources, options)
+ end
end
def responder
@@ -258,6 +242,29 @@ module ActionController #:nodoc:
end
end
+ # Receives a collection of mimes and a block with formats and initialize a
+ # collector. If a response was added to the collector, uses it to satisfy
+ # the request, otherwise yields the block given.
+ #
+ def collect_mimes_for_render(mimes, formats)
+ collector = Collector.new
+ mimes = collect_mimes_from_class_level if mimes.empty?
+ mimes.each { |mime| collector.send(mime) }
+ formats.call(collector) if formats
+
+ if format = request.negotiate_mime(collector.order)
+ self.formats = [format.to_sym]
+
+ if response = collector.response_for(format)
+ response.call
+ else
+ yield
+ end
+ else
+ head :not_acceptable
+ end
+ end
+
class Collector #:nodoc:
attr_accessor :order