Module: RailsAuditLog::Auditable

Extended by:
ActiveSupport::Concern
Defined in:
app/concerns/rails_audit_log/auditable.rb

Overview

Include in any ActiveRecord model to automatically track create, update, and destroy events as AuditLogEntry records.

Basic usage

class Article < ApplicationRecord
  include RailsAuditLog::Auditable
end

Configuring tracking

class Article < ApplicationRecord
  include RailsAuditLog::Auditable
  audit_log only: %i[title body],
            meta: { tenant_id: -> { Current.tenant_id } },
            version_limit: 50,
            async: true
end

Adds a polymorphic has_many :audit_log_entries association to the model.

Instance Method Summary collapse

Instance Method Details

#skip_audit_log { ... } ⇒ Object

Executes the block with audit logging disabled for this record’s writes. A convenience wrapper around RailsAuditLog.disable.

Examples:

Skip auditing during a bulk update

post.skip_audit_log { post.update!(cached_at: Time.current) }

Yields:

  • executes the block without recording any audit entries

Returns:

  • (Object)

    the return value of the block



142
143
144
# File 'app/concerns/rails_audit_log/auditable.rb', line 142

def skip_audit_log
  RailsAuditLog.disable { yield }
end