Search code examples
ruby-on-railsactiveresource

Why to_xml on ActiveResource does not work well?


I have several ActiveResource model in my project. There was so strange to me when I called to_xml on my ActiveResource. The options that I passed to to_xml like :only and :except doesn't work at all. On ActiveRecord, it works really well. Anyone knows?

class Node < ActiveResource::Base
   self.site = NODE_SERVER
end

# node has uuid, name, type attributes
node = Node.find("3333")
node.to_xml(:only => [:uuid])

# after here, i still get all attributes

Solution

  • The implementation of ActiveResource::Base#to_xml is different than ActiveRecord::Base.

    See http://api.rubyonrails.org/classes/ActiveResource/Base.html#M000914

    ActiveResource::Base#to_xml only accepts :indent, :dasherize, :camelize and :skip_instruct.