diff options
author | Ryan Bigg <radarlistener@gmail.com> | 2008-10-18 17:43:38 +1030 |
---|---|---|
committer | Ryan Bigg <radarlistener@gmail.com> | 2008-10-18 17:43:38 +1030 |
commit | 2139a1b6812be7ca86de2df52e9776a2be4a2bf7 (patch) | |
tree | 3131e29d3582b8aa1ba1c68710f327ce2f22aa1d /activeresource/lib | |
parent | 09b7e351316cb87a815678241fc90af549327cf3 (diff) | |
parent | 095cafbcd7fbae3baa845b23b93c8dca93b442f8 (diff) | |
download | rails-2139a1b6812be7ca86de2df52e9776a2be4a2bf7.tar.gz rails-2139a1b6812be7ca86de2df52e9776a2be4a2bf7.tar.bz2 rails-2139a1b6812be7ca86de2df52e9776a2be4a2bf7.zip |
Merge branch 'master' of git@github.com:lifo/docrails
Diffstat (limited to 'activeresource/lib')
-rw-r--r-- | activeresource/lib/active_resource/base.rb | 36 | ||||
-rw-r--r-- | activeresource/lib/active_resource/formats/json_format.rb | 2 |
2 files changed, 37 insertions, 1 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 74d8128c0e..bb284803d8 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -854,6 +854,42 @@ module ActiveResource # # my_group.to_xml(:skip_instruct => true) # # => <subsidiary_group> [...] </subsidiary_group> + def to_xml(options={}) + attributes.to_xml({:root => self.class.element_name}.merge(options)) + end + + # Returns a JSON string representing the model. Some configuration is + # available through +options+. + # + # ==== Options + # The +options+ are passed to the +to_json+ method on each + # attribute, so the same options as the +to_json+ methods in + # Active Support. + # + # * <tt>:only</tt> - Only include the specified attribute or list of + # attributes in the serialized output. Attribute names must be specified + # as strings. + # * <tt>:except</tt> - Do not include the specified attribute or list of + # attributes in the serialized output. Attribute names must be specified + # as strings. + # + # ==== Examples + # person = Person.new(:first_name => "Jim", :last_name => "Smith") + # person.to_json + # # => {"first_name": "Jim", "last_name": "Smith"} + # + # person.to_json(:only => ["first_name"]) + # # => {"first_name": "Jim"} + # + # person.to_json(:except => ["first_name"]) + # # => {"last_name": "Smith"} + def to_json(options={}) + attributes.to_json(options) + end + + # Returns the serialized string representation of the resource in the configured + # serialization format specified in ActiveResource::Base.format. The options + # applicable depend on the configured encoding format. def encode(options={}) case self.class.format when ActiveResource::Formats[:xml] diff --git a/activeresource/lib/active_resource/formats/json_format.rb b/activeresource/lib/active_resource/formats/json_format.rb index 9e269d4ded..1d88fc5f16 100644 --- a/activeresource/lib/active_resource/formats/json_format.rb +++ b/activeresource/lib/active_resource/formats/json_format.rb @@ -12,7 +12,7 @@ module ActiveResource end def encode(hash, options={}) - hash.to_json + hash.to_json(options) end def decode(json) |