---
title: "Rails 5 adds after_commit callbacks aliases"
description:
  "Rails 5 Introduces after_{create,update,delete}_commit callbacks as aliases
  for after_commit."
canonical_url: "https://www.bigbinary.com/blog/rails-5-adds-after_create-aliases"
markdown_url: "https://www.bigbinary.com/blog/rails-5-adds-after_create-aliases.md"
---

# Rails 5 adds after_commit callbacks aliases

Rails 5 Introduces after\_{create,update,delete}\_commit callbacks as aliases
for after_commit.

- Author: Hitesh Rawal
- Published: May 11, 2016
- Categories: Rails 5, Rails

Rails 4.x has
[after_commit](http://guides.rubyonrails.org/active_record_callbacks.html)
callback. `after_commit` is called after a record has been created, updated or
destroyed.

```ruby
class User < ActiveRecord::Base
  after_commit :send_welcome_mail, on: create
  after_commit :send_profile_update_notification, on: update
  after_commit :remove_profile_data, on: destroy

  def send_welcome_mail
    EmailSender.send_welcome_mail(email: email)
  end
end
```

## Rails 5 added new aliases

Rails 5 [had added](https://github.com/rails/rails/pull/22516) following three
aliases.

- after_create_commit
- after_update_commit
- after_destroy_commit

Here is revised code after using these aliases.

```ruby
class User < ApplicationRecord
  after_create_commit	:send_welcome_mail
  after_update_commit	:send_profile_update_notification
  after_destroy_commit	:remove_profile_data

  def send_welcome_mail
    EmailSender.send_welcome_mail(email: email)
  end
end
```

### Note

We earlier stated that `after_commit` callback is executed at the end of
transaction. Using `after_commit` with a transaction block can be tricky. Please
checkout our earlier post about
[Gotcha with after_commit callback in Rails](gotcha-with-after_commit-callback-in-rails)
.

## Links

- [Human page](https://www.bigbinary.com/blog/rails-5-adds-after_create-aliases)
