Rails had provided an
after_commit callback for ActiveRecord objects.
It is called after a record has been
We can also use below shortcut of
after_commit when creating, updating or
destroying a record respectively:
Rails has a separate shortcut for create and update, but a common callback for creating or updating a record was missing.
Rails 6 introduces a shortcut for
after_commit :hook, on: [:create, :update]
Before Rails 6:
In Rails 6:
With the introduction of
after_save_commit the above example can be
changed to below: