When do I need to reload?

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?

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

Sorry, 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

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