Store transaction changes for active record objects so that they are available in an after_commit callbacks.
Add this line to your application's Gemfile:
gem 'ar_transaction_changes'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ar_transaction_changes
Just include ArTransactionChanges and transaction_changed_attributes will store the original values for all the changed attributes throughout the transaction.
class User < ActiveRecord::Base
include ArTransactionChanges
after_commit :print_transaction_changes
def print_transaction_changes
transaction_changed_attributes.each do |name, old_value|
puts "attribute #{name}: #{old_value.inspect} -> #{send(name).inspect}"
end
end
end
- Fork it
- 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 new Pull Request