I was a little surprised to discover that when you update an association through nested attributes, it won’t touch the parent record. It makes sense when you consider that Rails is optimizing by not writing records that have not changed, but if were using updated_at on the model for caching you may be surprised.
This code will not change updated at on the post record:
As shown in the log:
The fix is very simple. Just touch the post record from the comment if you need updated_at to change on posts.
And now our post is updated:
Of course there are other ways to do this…