Rendering XML from the result of a find


I am quite new to Rails.

I have a model, store with
belongs_to :owner

in my controller I have

@store = Store.find(199, :include => :owner)
render :xml @store.to_xml

The result is that the xml only contains the store data, not the owners
data, even though it has retrieved the owners data along with the store.

How can I get the owner data to be included in the XML.

Is it possible to get just specific fields into the XML, such as



You should see this page:

To include owners data: @store.to_xml(:include => “owner”)
To show only specific field, use :only or :except options.

I tried it out with the include. It wasn’t giving me the results I
wanted, so I will try to use Builder Templates and do my own XML.

Using render gives the owner data in a child node under a store. What I
wanted was to have the nodes, such as at the same level as
the store.


I take back what I said, about not having the correct format. I found a
way to access the nested xml values, so I don’t need to use builder.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs