aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-07-30 22:43:37 +0200
committerJosé Valim <jose.valim@gmail.com>2009-07-30 22:43:37 +0200
commit7a4a679dbada2e1fcfc28db8c47dd32e03afc1af (patch)
treec671ac1d25b7da345a9396d7192668af7ffb1308
parent2c2ca833a531d825d9b46e501b564a52a8a69358 (diff)
downloadrails-7a4a679dbada2e1fcfc28db8c47dd32e03afc1af.tar.gz
rails-7a4a679dbada2e1fcfc28db8c47dd32e03afc1af.tar.bz2
rails-7a4a679dbada2e1fcfc28db8c47dd32e03afc1af.zip
Remove any resource logic from respond_to.
-rw-r--r--actionpack/lib/action_controller/base/mime_responds.rb31
1 files changed, 14 insertions, 17 deletions
diff --git a/actionpack/lib/action_controller/base/mime_responds.rb b/actionpack/lib/action_controller/base/mime_responds.rb
index f4a4007a43..485668d543 100644
--- a/actionpack/lib/action_controller/base/mime_responds.rb
+++ b/actionpack/lib/action_controller/base/mime_responds.rb
@@ -177,19 +177,21 @@ module ActionController #:nodoc:
# Be sure to check respond_with and respond_to documentation for more examples.
#
def respond_to(*mimes, &block)
- options = mimes.extract_options!
raise ArgumentError, "respond_to takes either types or a block, never both" if mimes.any? && block_given?
- resource = options.delete(:with)
responder = Responder.new
-
mimes = collect_mimes_from_class_level if mimes.empty?
mimes.each { |mime| responder.send(mime) }
block.call(responder) if block_given?
if format = request.negotiate_mime(responder.order)
- respond_to_block_or_template_or_resource(format, resource,
- options, &responder.response_for(format))
+ self.formats = [format.to_sym]
+
+ if response = responder.response_for(format)
+ response.call
+ else
+ default_render
+ end
else
head :not_acceptable
end
@@ -257,26 +259,21 @@ module ActionController #:nodoc:
# end
#
def respond_with(resource, options={}, &block)
- respond_to(options.merge!(:with => resource), &block)
- end
-
- protected
-
- def respond_to_block_or_template_or_resource(format, resource, options)
- self.formats = [format.to_sym]
- return yield if block_given?
-
begin
- default_render
+ respond_to(&block)
rescue ActionView::MissingTemplate => e
- if resource && resource.respond_to?(:"to_#{format.to_sym}")
- render options.merge(format.to_sym => resource)
+ format = self.formats.first
+
+ if resource.respond_to?(:"to_#{format}")
+ render options.merge(format => resource)
else
raise e
end
end
end
+ protected
+
# Collect mimes declared in the class method respond_to valid for the
# current action.
#