Skip to content

Instantly share code, notes, and snippets.

@adzap
Created October 30, 2012 22:12
Show Gist options
  • Save adzap/3983423 to your computer and use it in GitHub Desktop.
Save adzap/3983423 to your computer and use it in GitHub Desktop.
Add transaction ID to audit records
# Using XID gem https://github.com/adzap/xid
# with Audited gem https://github.com/collectiveidea/audited/commits/master
# This adds the transaction ID to the audit record so you can group all changes together which happened in the same transaction, # which is hopefully the same use action. This obviously needs you add a transaction_id column to the audits table.
Audited::Adapters::ActiveRecord::Audit.class_eval do
before_create :set_transaction_id
def set_transaction_id
self.transaction_id = ActiveRecord::Base.connection.transaction_id
nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment