RunAfterCommit
Run code in an ActiveRecord model after it is committed or immediately if you're outside of a transaction.
Installation
Add this line to your application's Gemfile:
gem 'run_after_commit'
And then execute:
$ bundle
Or install it yourself as:
$ gem install run_after_commit
Usage
Include RunAfterCommit
in your model and queue some code:
class SomeModel < ActiveRecord::Base
include RunAfterCommit
after_save :some_method
def some_method
run_after_commit do
# Runs when the transaction is committed
end
end
end
Contributing
- Fork it ( https://github.com/mrkamel/run_after_commit/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request