|
|
Question : Ruby On Rails, Joins? - - - Returning in XML
|
|
I am trying to return an object retrieved from a database as xml in ruby on rails.
It is a person object that has a "has many" relationship with "pets"
My source is a bit like this:
customer = Person.find(:first,:condition => ["id"=?",person_id], :select=> 'last_name,first_name,id') their_pets = customer.pets.find(:all,:select => 'name,species,id')
render :xml => customer.to_xml
This does not return any of the pet information. I can return the pet information by doing their_pets.to_xml. I need to returned the joined information in one XML file.
I tried: customer.pets << their_pets customer.to_xml
but that only returned the customer info, not the pet info.
|
Answer : Ruby On Rails, Joins? - - - Returning in XML
|
|
Nevermind I got it. Used REXML. Created document object, added roots nodes, looped through the their_pets and added pet nodes.
|
|
|
|
|