From 4d63e01fa052749f742e90bcb3889cbae6152c92 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Wed, 20 Sep 2006 19:31:17 +0000 Subject: fixed failing tests now that non-GET requests are sent with .xml file ext. Extracted #id_from_response as an entry point for customizing how a created resource gets its own ID. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5153 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activeresource/lib/active_resource/base.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'activeresource/lib') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 89724b1814..647fd90bb5 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -164,10 +164,15 @@ module ActiveResource def create returning connection.post(self.class.collection_path(prefix_options), to_xml) do |resp| - self.id = resp['Location'][/\/([^\/]*?)(\.\w+)?$/, 1] + self.id = id_from_response(resp) end end + # takes a response from a typical create post and pulls the ID out + def id_from_response(response) + response['Location'][/\/([^\/]*?)(\.\w+)?$/, 1] + end + private def find_or_create_resource_for_collection(name) find_or_create_resource_for(name.to_s.singularize) -- cgit v1.2.3