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.
class ApplicationController < ActionController::Base
def info_for_paper_trail
# Default is: {}
{ :ip => request.remote_ip, :user_agent => request.user_agent }
end
end
class ApplicationController < ActionController::Base
def user_for_paper_trail
# Default is: current_user rescue nil
logged_in? ? current_user.name : 'Public user'
end
end
>> widget = widget.version_at 1.day.ago # the widget as it was one day ago
>> widget.save # reverted
# config/environments/test.rb
config.after_initialize do
PaperTrail.enabled = false
end
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.