开发者

In Rails 2, how would I define a callback method when adding models in a has_many relationship?

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 f开发者_开发知识库or looking!


You should use an after_create callback in the Post model.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜