3 ms·
Like the idea about after_commit callbacks. There's nothing nastier than a valid object saving (especially one calling an API somewhere else), and then that sa
by ExactoKnight 9y ago
Like the idea about after_commit callbacks. There's nothing nastier than a valid object saving (especially one calling an API somewhere else), and then that save rolling back due to a callback exception.
A good rule of thumb I heard about Model callbacks is they should only be used to persist or modify state about themselves. I.e. creating and persisting many other ActiveRecord relations, in response to a callback, is a road to misery.
I will also comment more generally that I believe notifications + callbacks is a very difficult area of Rails architecture that is not well handled in the MVC approach it provides.
I would look to Rails event store as a path for decoupling service objects even more, from the sequential actions that lead to their creation.