Hi, 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 owner.name Thanks Andrew -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
You should see this page: http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M000934 To include owners data: @store.to_xml(:include => "owner") To show only specific field, use :only or :except options. On 10/4/06, Andrew Cleland <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi, > > 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 > owner.name > > Thanks > > Andrew > > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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 owner.name at the same level as the store. Andrew -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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. Andrew -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---