Don P
Don P

Reputation: 63547

Only call Rails Active Record callback on successful model create

I want to add after_create :my_function to one of my models. How can I make sure this method is only called on successful creates or updates?

Upvotes: 1

Views: 1060

Answers (1)

Pete
Pete

Reputation: 18075

You'd want to use after_save. This callback is called on both create and updates (or, any call to the save method) so long as the callback chain isn't broken before the save completes (validation errors, etc). You can see some examples in the docs:

http://apidock.com/rails/ActiveRecord/Callbacks/after_save

Upvotes: 1

Related Questions