| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
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.
Please note: Rails 3 (and thus, ActiveRecord 3) provides commit callbacks natively, so this library will remain just for versions 1.2.x to 2.x of ActiveRecord.
gem install after_commit
The following callbacks are provided:
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
endKeep in mind that transactions are finicky at best in tests, and so there’s a helper module to make after_commit play nicely in your testing context. You’ll need to add these two lines to your spec/test helper:
ActiveRecord::Base.send(:include, AfterCommit::AfterSavepoint) ActiveRecord::Base.include_after_savepoint_extensions
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:
| Back | FazBrowse Home | New Git URL |