Sorry this page looks weird. It was automatically migrated from my old blog, which had a different layout and different CSS.

PaperTrail Improvements

PaperTrail is a gem which lets you easily track changes to your ActiveRecord models' data. Recently I pulled in some good work from Jeremy Weiskotten and Phan Le, while making some improvements of my own.

Here are the highlights of what changed between 1.4.0 and 1.5.0.

Easily store controller-level metadata

class ApplicationController < ActionController::Base
  def info_for_paper_trail
    # Default is: {}
    { :ip => request.remote_ip, :user_agent => request.user_agent }

Easily change how the controller figures out who was responsible

class ApplicationController < ActionController::Base
  def user_for_paper_trail
    # Default is: current_user rescue nil
    logged_in? ? : 'Public user'

Time-based recovery of models

>> widget = widget.version_at  # the widget as it was one day ago
>>                           # reverted

Global enable/disable (useful in your tests)

# config/environments/test.rb
config.after_initialize do
  PaperTrail.enabled = false

Invisible changes


Lots of people use PaperTrail in production and seem pretty happy with it. You can store any model-level or controller-level information alongside your models' versions, so it’s nice and easy to adapt to your specific needs. And of course it continues to work out of the box with zero configuration — that’s the way I like it.

See the README for more details.

Andrew Stewart • 31 March 2010 • RailsPaperTrail
You can reach me by email or on Twitter.