Alii.hart-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Hart
2007-Nov-01 22:49 UTC
newbie: need to delete object in loop
Hi, sorry for this rather simplistic question, but I can''t think of a good way of googling the answer (just been trying for 20 mins). Anyway... so I have this rather simplistic piece of code: <% for artwork in @artworks %> <% if artwork.medium_id %> <% medium = Medium.find(artwork.medium_id) %> <% end %> <% if medium %> <p><%= medium.name %></p> <% end %> <% end %> There are 6 artworks, but only the first one has a medium_id, the others are not set. When the code runs the medium is picked up in the first iteration of the loop, and then printed each subsequent iteration. I naively assumed that "medium" would be destroyed at the end of each loop, but it seems I was wrong. Is there any way for me to force its destruction? cheers, ali -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
> Hi, sorry for this rather simplistic question, but I can''t think of a > good way of googling the answer (just been trying for 20 mins). > Anyway... so I have this rather simplistic piece of code: > > <% for artwork in @artworks %><% medium = nil %>> > <% if artwork.medium_id %> > <% medium = Medium.find(artwork.medium_id) %> > <% end %> > > <% if medium %> > <p><%= medium.name %></p> > <% end %> > > <% end %> > > There are 6 artworks, but only the first one has a medium_id, the others > are not set. When the code runs the medium is picked up in the first > iteration of the loop, and then printed each subsequent iteration. > > I naively assumed that "medium" would be destroyed at the end of each > loop, but it seems I was wrong. Is there any way for me to force its > destruction? > > cheers, > > ali > -- > 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?hl=en -~----------~----~----~----~------~----~------~--~---