Hi, in this method update, after sort positions, at the block I haven''t objetcs! and it''s raised a nil object error... def update positions = self.league_positions positions.sort positions.each do |pos, i| pos.position = i + 1 <---------------- pos doesn''t exists pos.save end self.save end How could I resolve this?, Do I need to reload?, Which is the criteria I have to follow to reload objects? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > def update > positions = self.league_positions > positions.sort > positions.each do |pos, i| > pos.position = i + 1 <---------------- pos doesn''t exists > pos.save > end > self.save > endSorry, I had some mistakes, but the once fixed I have the same results: def update positions = self.league_positions ordered_positions = positions.sort i = 1 ordered_positions.each do |pos| pos.position = i i = i.next pos.save end self.save end --~--~---------~--~----~------------~-------~--~----~ 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 think today I have to be quiet :)... not a good day. I have several mistakes, one of them was to name the method ''update'', what a mistake!!! it made infinite loop!! Now it works... def update_positions positions = self.league_positions ordered_positions = positions.sort i = 1 ordered_positions.each do |pos| pos.position = i i = i.next pos.save end self.save end --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---