ruby-on-railscallbackafter-saveafter-create

Rails callback for after insert


I'm using a closure table to model the hierarchical structure of one of my models. As such, I am using an after_create hook to create the tree_path objects whenever Model.create is called. I would also like this hook to run whenever #new is called in conjunction with #save. This would imply that I would have to have to user after_save instead of after_create, however, after_save also runs on update, which I do not want.

Is there in which I can have the callback run on the initial insert of an object (on create or first save) but not on update? Is it bad form to be creating more objects from a callback?


Solution

  • After more investigation, it appears that after_create actually does run after save is called, only if the object hasn't been saved before as well as after create.