aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG6
-rwxr-xr-xactionpack/lib/action_controller/base.rb2
-rw-r--r--actionpack/test/controller/new_render_test.rb20
3 files changed, 26 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 90e5b6e975..7d7ba465f1 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,11 @@
*SVN*
+* Added url_for usage on render :location, which allows for record identification [DHH]. Example:
+
+ render :xml => person, :status => :created, :location => person
+
+ ...expands the location to person_url(person).
+
* Introduce the request.body stream. Lazy-read to parse parameters rather than always setting RAW_POST_DATA. Reduces the memory footprint of large binary PUT requests. [Jeremy Kemper]
* Add some performance enhancements to ActionView.
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index e3b52278ba..7afacd4f69 100755
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -775,7 +775,7 @@ module ActionController #:nodoc:
end
if location = options[:location]
- response.headers["Location"] = location
+ response.headers["Location"] = url_for(location)
end
if text = options[:text]
diff --git a/actionpack/test/controller/new_render_test.rb b/actionpack/test/controller/new_render_test.rb
index 18a32f6e30..fa27a1794b 100644
--- a/actionpack/test/controller/new_render_test.rb
+++ b/actionpack/test/controller/new_render_test.rb
@@ -1,6 +1,9 @@
require File.dirname(__FILE__) + '/../abstract_unit'
-silence_warnings { Customer = Struct.new("Customer", :name) }
+silence_warnings { Customer = Struct.new(:name, :id) }
+
+class CustomersController < ActionController::Base
+end
module Fun
class GamesController < ActionController::Base
@@ -261,6 +264,11 @@ class NewRenderTestController < ActionController::Base
def render_with_location
render :xml => "<hello/>", :location => "http://example.com", :status => 201
end
+
+ def render_with_object_location
+ customer = Customer.new("Some guy", 1)
+ render :xml => "<customer/>", :location => customer_url(customer), :status => :created
+ end
def render_with_to_xml
to_xmlable = Class.new do
@@ -766,4 +774,14 @@ EOS
get :render_with_to_xml
assert_equal "<i-am-xml/>", @response.body
end
+
+ def test_rendering_with_object_location_should_set_header_with_url_for
+ ActionController::Routing::Routes.draw do |map|
+ map.resources :customers
+ map.connect ':controller/:action/:id'
+ end
+
+ get :render_with_object_location
+ assert_equal "http://test.host/customers/1", @response.headers["Location"]
+ end
end \ No newline at end of file