aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2007-10-07 02:13:51 +0000
committerMichael Koziarski <michael@koziarski.com>2007-10-07 02:13:51 +0000
commitf29ae1253538b1182c2cabfcfbcc8f8b70bab575 (patch)
treeea58b3a542108ec020add426aa90979d1975b6cd /activeresource
parentf118a5b05b898e57ff4696fd6cbf91de81c079ea (diff)
downloadrails-f29ae1253538b1182c2cabfcfbcc8f8b70bab575.tar.gz
rails-f29ae1253538b1182c2cabfcfbcc8f8b70bab575.tar.bz2
rails-f29ae1253538b1182c2cabfcfbcc8f8b70bab575.zip
Add Base#to_param to Active Resource that quacks like ActiveRecord. Closes #9557 [bradediger]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7764 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource')
-rw-r--r--activeresource/lib/active_resource/base.rb5
-rw-r--r--activeresource/test/base_test.rb7
2 files changed, 12 insertions, 0 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index 9fb347d2c3..b1a79731b9 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -550,6 +550,11 @@ module ActiveResource
attributes[self.class.primary_key] = id
end
+ # Allows ActiveResource objects to be used as parameters in ActionPack URL generation.
+ def to_param
+ id && id.to_s
+ end
+
# Test for equality. Resource are equal if and only if +other+ is the same object or
# is an instance of the same class, is not +new?+, and has the same +id+.
#
diff --git a/activeresource/test/base_test.rb b/activeresource/test/base_test.rb
index f97b08295a..89bc28deda 100644
--- a/activeresource/test/base_test.rb
+++ b/activeresource/test/base_test.rb
@@ -444,4 +444,11 @@ class BaseTest < Test::Unit::TestCase
assert xml.include?('<name>Matz</name>')
assert xml.include?('<id type="integer">1</id>')
end
+
+ def test_to_param_quacks_like_active_record
+ new_person = Person.new
+ assert_nil new_person.to_param
+ matz = Person.find(1)
+ assert_equal '1', matz.to_param
+ end
end