diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2010-05-12 15:31:37 -0300 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-05-12 21:02:31 +0200 |
commit | 903637f5f0a1a9789fa12da1519e028b9faa37d8 (patch) | |
tree | cb99d4de129e0d5f91c5478dda83b52fbb66b459 | |
parent | 6334006b815eadd83575fe6d00e9010838530ee7 (diff) | |
download | rails-903637f5f0a1a9789fa12da1519e028b9faa37d8.tar.gz rails-903637f5f0a1a9789fa12da1519e028b9faa37d8.tar.bz2 rails-903637f5f0a1a9789fa12da1519e028b9faa37d8.zip |
Fixes to_json and to_xml for ActiveResource
Signed-off-by: José Valim <jose.valim@gmail.com>
-rw-r--r-- | activeresource/lib/active_resource/base.rb | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 15d77df3b5..ffdb5fb50a 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -552,19 +552,20 @@ module ActiveResource end def element_name - model_name.element + @element_name ||= model_name.element end - def element_name=(value) - model_name.element = value + def element_name=(element_name) + @element_name = element_name + @collection_name ||= model_name.collection.sub(/[^\/]*$/, @element_name.pluralize) end def collection_name - model_name.collection + @collection_name ||= model_name.collection end - def collection_name=(value) - model_name.collection = value + def collection_name=(collection_name) + @collection_name = collection_name end attr_accessor_with_default(:primary_key, 'id') #:nodoc: @@ -1306,6 +1307,14 @@ module ActiveResource end end + def to_json(options={}) + super({ :root => self.class.element_name }.merge(options)) + end + + def to_xml(options={}) + super({ :root => self.class.element_name }.merge(options)) + end + protected def connection(refresh = false) self.class.connection(refresh) |