aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-06-26 15:48:47 +0200
committerJosé Valim <jose.valim@gmail.com>2010-06-26 15:48:47 +0200
commit7eb5766bd1d7300e598fb81769da79ffbaa7b62a (patch)
tree1c6d7caa191aaa20cfbf4454853d2fc414dc4287
parent3782010377a7774c27011ff57e0e783b0f85a928 (diff)
downloadrails-7eb5766bd1d7300e598fb81769da79ffbaa7b62a.tar.gz
rails-7eb5766bd1d7300e598fb81769da79ffbaa7b62a.tar.bz2
rails-7eb5766bd1d7300e598fb81769da79ffbaa7b62a.zip
Small changes to responder:
* resources is always an array; * Lazy retrieve request and formats; * Alias api_location and navigation_location to resource_location, making easier to change its behavior without affecting each other and without a need to reimplement any of the behavior methods.
-rw-r--r--actionpack/lib/action_controller/metal/responder.rb18
1 files changed, 13 insertions, 5 deletions
diff --git a/actionpack/lib/action_controller/metal/responder.rb b/actionpack/lib/action_controller/metal/responder.rb
index 22bdcd0f3c..cb644dfd16 100644
--- a/actionpack/lib/action_controller/metal/responder.rb
+++ b/actionpack/lib/action_controller/metal/responder.rb
@@ -89,9 +89,7 @@ module ActionController #:nodoc:
def initialize(controller, resources, options={})
@controller = controller
- @request = controller.request
- @format = controller.formats.first
- @resource = resources.is_a?(Array) ? resources.last : resources
+ @resource = resources.last
@resources = resources
@options = options
@action = options.delete(:action)
@@ -101,6 +99,14 @@ module ActionController #:nodoc:
delegate :head, :render, :redirect_to, :to => :controller
delegate :get?, :post?, :put?, :delete?, :to => :request
+ def request
+ @request ||= @controller.request
+ end
+
+ def format
+ @format ||= @controller.formats.first
+ end
+
# Undefine :to_json and :to_yaml since it's defined on Object
undef_method(:to_json) if method_defined?(:to_json)
undef_method(:to_yaml) if method_defined?(:to_yaml)
@@ -147,7 +153,7 @@ module ActionController #:nodoc:
elsif has_errors? && default_action
render :action => default_action
else
- redirect_to resource_location
+ redirect_to navigation_location
end
end
@@ -160,7 +166,7 @@ module ActionController #:nodoc:
elsif has_errors?
display resource.errors, :status => :unprocessable_entity
elsif post?
- display resource, :status => :created, :location => resource_location
+ display resource, :status => :created, :location => api_location
else
head :ok
end
@@ -178,6 +184,8 @@ module ActionController #:nodoc:
def resource_location
options[:location] || resources
end
+ alias :navigation_location :resource_location
+ alias :api_location :resource_location
# If a given response block was given, use it, otherwise call render on
# controller.