aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/metal/responder.rb
diff options
context:
space:
mode:
authorSzymon Nowak <szimek@gmail.com>2010-10-11 19:37:03 +0200
committerJosé Valim <jose.valim@gmail.com>2010-10-12 00:56:07 +0200
commit0d3333257156544feba729ba28f6874d5a30d561 (patch)
tree2c2fa4a38b6825c53a72d4c8d3832efdd2f9eed7 /actionpack/lib/action_controller/metal/responder.rb
parent582a088ba7f3e720a259f6e01b3fabcda87484b7 (diff)
downloadrails-0d3333257156544feba729ba28f6874d5a30d561.tar.gz
rails-0d3333257156544feba729ba28f6874d5a30d561.tar.bz2
rails-0d3333257156544feba729ba28f6874d5a30d561.zip
Return a valid empty JSON on successful PUT and DELETE requests. [#5199 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionpack/lib/action_controller/metal/responder.rb')
-rw-r--r--actionpack/lib/action_controller/metal/responder.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/metal/responder.rb b/actionpack/lib/action_controller/metal/responder.rb
index 851925e1b7..38d32211cc 100644
--- a/actionpack/lib/action_controller/metal/responder.rb
+++ b/actionpack/lib/action_controller/metal/responder.rb
@@ -161,6 +161,8 @@ module ActionController #:nodoc:
display resource.errors, :status => :unprocessable_entity
elsif post?
display resource, :status => :created, :location => api_location
+ elsif has_empty_resource_definition?
+ display empty_resource, :status => :ok
else
head :ok
end
@@ -221,5 +223,23 @@ module ActionController #:nodoc:
def default_action
@action ||= ACTIONS_FOR_VERBS[request.request_method_symbol]
end
+
+ # Check whether resource needs a specific definition of empty resource to be valid
+ #
+ def has_empty_resource_definition?
+ respond_to?("empty_#{format}_resource")
+ end
+
+ # Delegate to proper empty resource method
+ #
+ def empty_resource
+ send("empty_#{format}_resource")
+ end
+
+ # Return a valid empty JSON resource
+ #
+ def empty_json_resource
+ "{}"
+ end
end
end