Skip to content

A Ruby on Rails plugin to add an after_commit callback. This can be used to trigger things only after the entire transaction is complete.

License

Notifications You must be signed in to change notification settings

packagethief/after_commit

This branch is 55 commits behind pat/after_commit:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

6fe6463 · Dec 15, 2009

History

43 Commits
Dec 15, 2009
Dec 14, 2009
Dec 14, 2009
Sep 1, 2009
May 31, 2008
Nov 25, 2009
Dec 14, 2009
Nov 25, 2009
Nov 25, 2009
Nov 25, 2009

Repository files navigation

after_commit

An ActiveRecord/Rails library to add before_commit, after_commit, before_rollback and after_rollback callbacks. These callbacks are focused on the transactions, instead of specific model actions. This is beneficial in situations where you are doing asynchronous processing and need committed objects.

Installation

gem install after_commit --source http://gemcutter.org

Usage

The following callbacks are provided:

  • before_commit
  • before_commit_on_create
  • before_commit_on_update
  • before_commit_on_destroy
  • after_commit
  • after_commit_on_create
  • after_commit_on_update
  • after_commit_on_destroy
  • before_rollback
  • after_rollback

You can use these just like you would any other callback:

class Article < ActiveRecord::Base
  after_commit :method_to_call_after_commit
  
  # ...
  
  private
  
  def method_to_call_after_commit
    # Do something knowing that the transaction is committed.
  end
end

Credits

This code first appeared in a blog post by Eli Miller, and was then included in Thinking Sphinx by Pat Allan, with modifications from Joost Hietbrink. The code was then put on GitHub as a plugin by Nick Muerdter, and many people forked and added their own contributions.

This version (maintained by Pat Allan) includes the following patches:

About

A Ruby on Rails plugin to add an after_commit callback. This can be used to trigger things only after the entire transaction is complete.

Resources

License

Stars

Watchers

Forks

Packages

No packages published