views:

30

answers:

2

In my project I have a Forum that has many Topics, and each Topic has many Posts. When I add a Post to a Topic, I would like to update a timestamp column in the Topic model to record when the last Post was added to the Topic. How can I do this?

Thank you for looking!

A: 

you can use the after_save callback in the model => http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html

ipsum
+1  A: 

You should use an after_create callback in the Post model.

wuputah
I've tried this, but the call back doesn't seems to run when a new Post is created. Maybe this has something to do with Post being a nested Resource?
jklina
Nevermind, my problem was that I wasn't saving the topic after I was timestamping it :x
jklina