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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.