diff options
author | Josh Kalderimis <josh.kalderimis@gmail.com> | 2011-03-31 18:18:11 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-03-31 18:53:27 +0200 |
commit | 48404a751d7cab1556c390a5915c90947d56b46e (patch) | |
tree | 0c28195bb20eb05c8cb745a7218570d4d292fc71 /actionpack/lib/action_controller/metal | |
parent | 9766997f4ce26fe0d97d7b9eebf885ddb517c80c (diff) | |
download | rails-48404a751d7cab1556c390a5915c90947d56b46e.tar.gz rails-48404a751d7cab1556c390a5915c90947d56b46e.tar.bz2 rails-48404a751d7cab1556c390a5915c90947d56b46e.zip |
only try to display an api template in responders if the request is a get or there are no errors
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionpack/lib/action_controller/metal')
-rw-r--r-- | actionpack/lib/action_controller/metal/responder.rb | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/actionpack/lib/action_controller/metal/responder.rb b/actionpack/lib/action_controller/metal/responder.rb index 82d11c8481..3862a68b44 100644 --- a/actionpack/lib/action_controller/metal/responder.rb +++ b/actionpack/lib/action_controller/metal/responder.rb @@ -131,7 +131,11 @@ module ActionController #:nodoc: # responds to :to_format and display it. # def to_format - default_render + if get? || !has_errors? + default_render + else + display_errors + end rescue ActionView::MissingTemplate => e api_behavior(e) end @@ -155,9 +159,6 @@ module ActionController #:nodoc: if get? display resource - elsif has_errors? - # bypass the options merging of display - controller.render format => resource.errors, :status => :unprocessable_entity elsif post? display resource, :status => :created, :location => api_location elsif has_empty_resource_definition? @@ -210,6 +211,10 @@ module ActionController #:nodoc: controller.render given_options.merge!(options).merge!(format => resource) end + def display_errors + controller.render format => resource.errors, :status => :unprocessable_entity + end + # Check whether the resource has errors. # def has_errors? |