I have a model called Tournament, which has_many Entries. There is a method in Tournament called reset_rankings, which traverses all of its entries and updates the current_rank field of each entry based on how many points that entry currently has. I call entry.save on each entry I update in this traversal.
This method seems to update the entries in memory just fine, but when I reload the Tournament I was working with, the current_rank fields all revert to what they were before calling reset_rankings.
I tried calling tournament.save after calling reset_rankings but that still didn’t persist the changes
I am sure I am doing something stupid, but the rails magic isn’t working like I expect.
When you call entry.save, are you checking the return value? If false then the save was blocked for some reason, eg didn’t pass your validations.
Or change foo.save to foo.save! to raise an error when the save fails.