Skip to content
Browse files

Fixes to_json and to_xml for ActiveResource

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 6334006 commit 903637f5f0a1a9789fa12da1519e028b9faa37d8 @spastorino spastorino committed with josevalim May 12, 2010
Showing with 15 additions and 6 deletions.
  1. +15 −6 activeresource/lib/active_resource/base.rb
View
21 activeresource/lib/active_resource/base.rb
@@ -552,19 +552,20 @@ def headers
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 @@ def respond_to?(method, include_priv = false)
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)

0 comments on commit 903637f

Please sign in to comment.
Something went wrong with that request. Please try again.