Hey, i have overwritten the to_xml method with these: http://pastie.org/793456 and i call it with: render :xml => Focat.find(:all) but the xml elements are displayed twice! could someone see my failure? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 26, 11:42 am, Stephan Hagios <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hey, > i have overwritten the to_xml method with these:http://pastie.org/793456 > and i call it with: > render :xml => Focat.find(:all) > but the xml elements are displayed twice! > could someone see my failure?rails will call to_xml on all each member of the collection, but it looks like your to_xml is doing a second Focat.find(:all). Fred> -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On Jan 26, 11:42�am, Stephan Hagios <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Hey, >> i have overwritten the to_xml method with these:http://pastie.org/793456 >> and i call it with: >> render :xml => Focat.find(:all) >> but the xml elements are �displayed twice! >> could someone see my failure? > > rails will call to_xml on all each member of the collection, but it > looks like your to_xml is doing a second Focat.find(:all). > > Fredi found out that to_xml is called twice. but how can i solve this problem? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 26, 12:02 pm, Stephan Hagios <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > i found out that to_xml is called twice. but how can i solve this > problem?Like i said you shouldn''t be doing that Focat.all inside your to_xml method - rails is already iterating over that collection for you Fred> -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On Jan 26, 12:02�pm, Stephan Hagios <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> >> i found out that to_xml is called twice. but how can i solve this >> problem? > > Like i said you shouldn''t be doing that Focat.all inside your to_xml > method - rails is already iterating over that collection for you > > Fredhow does rails that do? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 26, 12:40 pm, Stephan Hagios <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Frederick Cheung wrote: > > On Jan 26, 12:02 pm, Stephan Hagios <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > >> i found out that to_xml is called twice. but how can i solve this > >> problem? > > > Like i said you shouldn''t be doing that Focat.all inside your to_xml > > method - rails is already iterating over that collection for you > > > Fred > > how does rails that do?You''ve called render :xml, passing an array. Rails calls to_xml on the array, which in turns calls to_xml on every element of the array. Fred> -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On Jan 26, 12:40�pm, Stephan Hagios <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> >> how does rails that do? > > You''ve called render :xml, passing an array. Rails calls to_xml on the > array, which in turns calls to_xml on every element of the array. > > Fredok, but i need this strukture of the xml file, where i show focats and fotos. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 26, 12:48 pm, Stephan Hagios <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Frederick Cheung wrote: > > On Jan 26, 12:40 pm, Stephan Hagios <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > >> how does rails that do? > > > You''ve called render :xml, passing an array. Rails calls to_xml on the > > array, which in turns calls to_xml on every element of the array. > > > Fred > > ok, but i need this strukture of the xml file, where i show focats and > fotos.that''s fine, but if you want to be able to write render :xml => Focat.all then you need to let rails do the outermost iteration. You may not care about that at all though - you can generate your xml separately and then do render :xml => some_xml Fred> > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On Jan 26, 12:48�pm, Stephan Hagios <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> ok, but i need this strukture of the xml file, where i show focats and >> fotos. > > that''s fine, but if you want to be able to write render :xml => > Focat.all then you need to let rails do the outermost iteration. You > may not care about that at all though - you can generate your xml > separately and then do render :xml => some_xml > Fredhey, now i tried it with: @focats = Focat.find(:all) xml = @focats.to_xml render :xml => xml but also the entries are twice. i dont get it. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 26, 1:19 pm, Stephan Hagios <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Frederick Cheung wrote: > > On Jan 26, 12:48 pm, Stephan Hagios <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> ok, but i need this strukture of the xml file, where i show focats and > >> fotos. > > > that''s fine, but if you want to be able to write render :xml => > > Focat.all then you need to let rails do the outermost iteration. You > > may not care about that at all though - you can generate your xml > > separately and then do render :xml => some_xml > > Fred > > hey, now i tried it with: > @focats = Focat.find(:all) > xml = @focats.to_xml > render :xml => xml > but also the entries are twice. i dont get it. >This code is basically identical to the previous version (it''s just spelling out what rails was doing for you). The to_xml method on arrays calls to_xml on every single object in the array. Fred> -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On Jan 26, 1:19�pm, Stephan Hagios <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> >> hey, now i tried it with: >> @focats = Focat.find(:all) >> xml = @focats.to_xml >> render :xml => xml >> but also the entries are twice. i dont get it. >> > This code is basically identical to the previous version (it''s just > spelling out what rails was doing for you). The to_xml method on > arrays calls to_xml on every single object in the array. > > Frednow i get it, thank u so much! -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.