No commit activity in last 3 years
No release in over 3 years
Adds the following callbacks to your ActiveRecord objects and observers: after_commit_on_create, after_commit_on_update, after_commit_on_save, after_commit_on_destroy.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

>= 4.0
 Project Readme

After Commit on Action

Move your after_commit callbacks to your Rails Observers.

If you are defining an after_commit block in your Rails model directly, you have the option to specify when (on create, update, destroy) that block should be run.

Example:

class Foo
  after_commit :on => :create do
    send_create_email
  end

  after_commit :on => :update do
    send_update_email
  end
  
  after_commit :on => :destroy do
    send_destroy_email
  end
end

If you wanted to move this code to your observers, you will find that you cannot specify the on option. To remedy that limitation, this gem allows you to create the following callbacks in your Rails Observers:

  • after_commit_on_create
  • after_commit_on_update
  • after_commit_on_save
  • after_commit_on_destroy

Example:

class Foo
end

class FooObserver < ActiveRecord::Observer
  observe :foo

  def after_commit_on_create(foo)
    send_create_email
  end

  def after_commit_on_update(foo)
    send_update_email
  end

  def after_commit_on_save(foo)
    send_save_email
  end

  def after_commit_on_destroy(foo)
    send_destroy_email
  end