mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fixes to_json and to_xml for ActiveResource
Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
parent
6334006b81
commit
903637f5f0
1 changed files with 15 additions and 6 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue