Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # I want more control of how my model gets serialized into XML. I was toying with an idea... along the lines of
- class User
- property :user_name, String
- property :domain, String
- has_one :contact
- when_serializing :name => 'user', :show_id => 'true'
- serialize :user_name, :formats => [:xml,:json], :contexts => [:summary, :detailed]
- serialize :domain, :formats => [:xml], :contexts => [:detailed]
- serialize :contact, :formats => [:xml], :context => [:detailed]
- end
- class Contact
- property :first_name, String
- property :last_name, String
- serialize :first_name, :formats => [:xml,:json], :contexts => [:summary, :detailed]
- serialize :last_name, :formats => [:xml,:json], :contexts => [:summary,:detailed]
- end
- # and then you could do
- User.first(:user_name => 'joe').to_xml(:detailed)
- # or (with some magic on array)
- User.all().to_xml(:summary)
Add Comment
Please, Sign In to add comment