explaingit

paper-trail-gem/paper_trail

7,000RubyAudience · developerComplexity · 2/5Setup · easy

TLDR

Ruby gem for Rails apps that automatically records every create, update, and delete on your database records, giving you a full change history you can browse, diff, or roll back at any time.

Mindmap

mindmap
  root((paper_trail))
    What it does
      Records all changes
      Full version history
      Restore past states
    Setup
      Add gem to project
      Run migration
      Add to model
    Features
      Who changed it
      When it changed
      Field-level control
    Testing
      RSpec helpers
      Minitest helpers
      Cucumber support
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add an audit trail to a Rails app to track who changed what record and when

USE CASE 2

Let users undo accidental edits by restoring a record to any previous version

USE CASE 3

Meet compliance requirements by keeping a tamper-evident log of all data changes

Tech stack

RubyRails

Getting it running

Difficulty · easy Time to first run · 30min

In plain English

PaperTrail is a Ruby gem for Rails applications that records every change made to your database records. When someone creates, updates, or deletes a record, PaperTrail saves a snapshot of what the record looked like before the change. You can then look back at the full history of any record, see exactly what changed and when, and restore a previous state if needed. This is useful for audit logs, undoing mistakes, or simply understanding how data changed over time. Setup involves three steps: adding the gem to your project, running a generator that creates a new database table called versions to store the history, and adding a single line to any model you want to track. After that, every tracked record gains a versions method that returns its full change history. Each saved version tells you what event occurred (create, update, or destroy), when it happened, and optionally who triggered it. If your app has a logged-in user concept, a one-line addition to your base controller wires up automatic tracking of who made each change. To restore a record to a past state, you call reify on a version object, which reconstructs the record as it existed at that point in time. You have fine-grained control over what gets tracked. You can choose to record only certain lifecycle events, skip tracking when specific conditions are met, include or exclude individual fields, or turn tracking off entirely for a block of code. There are also options to limit how many versions are kept, attach extra metadata to each version, and track changes to associated records. PaperTrail is one of the longest-standing gems in the Rails ecosystem, with a version history stretching back to Rails 2.3. It follows semantic versioning and ships with test helpers for Minitest, RSpec, and Cucumber. The full README is longer than what was shown.

Copy-paste prompts

Prompt 1
Show me how to add PaperTrail to a Rails model so every update is recorded, and how to display the change history in a view
Prompt 2
Using PaperTrail, write a Rails controller action that lets a user restore a record to its state from one week ago
Prompt 3
How do I configure PaperTrail to track which logged-in user made each change and store that in the versions table?
Prompt 4
I want to exclude a sensitive field like password_digest from PaperTrail tracking, show me how to set that up
Open on GitHub → Explain another repo

← paper-trail-gem on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.