aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-01-10 20:21:08 +0100
committerJosé Valim <jose.valim@gmail.com>2010-01-10 20:21:08 +0100
commitd2e7c1b97d1c2152eeb0669fe0b88989a087246c (patch)
treee9de0209cc1db822b773ab3c1e9480473f742364 /actionpack/lib
parent8d72ba51bac75e44ca86fafbcab54eab7a355d29 (diff)
downloadrails-d2e7c1b97d1c2152eeb0669fe0b88989a087246c.tar.gz
rails-d2e7c1b97d1c2152eeb0669fe0b88989a087246c.tar.bz2
rails-d2e7c1b97d1c2152eeb0669fe0b88989a087246c.zip
Raise an error if respond_with is invoked and no format is declared.
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller/metal/mime_responds.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb
index 468c5f4fae..4c02677729 100644
--- a/actionpack/lib/action_controller/metal/mime_responds.rb
+++ b/actionpack/lib/action_controller/metal/mime_responds.rb
@@ -215,7 +215,10 @@ module ActionController #:nodoc:
# a proc to it.
#
def respond_with(*resources, &block)
- if response = retrieve_response_from_mimes([], &block)
+ raise "In order to use respond_with, first you need to declare the formats your " <<
+ "controller responds to in the class level" if mimes_for_respond_to.empty?
+
+ if response = retrieve_response_from_mimes(&block)
options = resources.extract_options!
options.merge!(:default_response => response)
(options.delete(:responder) || responder).call(self, resources, options)
@@ -246,9 +249,9 @@ module ActionController #:nodoc:
# Collects mimes and return the response for the negotiated format. Returns
# nil if :not_acceptable was sent to the client.
#
- def retrieve_response_from_mimes(mimes, &block)
+ def retrieve_response_from_mimes(mimes=nil, &block)
collector = Collector.new { default_render }
- mimes = collect_mimes_from_class_level if mimes.empty?
+ mimes ||= collect_mimes_from_class_level
mimes.each { |mime| collector.send(mime) }
block.call(collector) if block_given?