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 }
end
end
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? ? current_user.name : 'Public user'
end
end
Time-based recovery of models
>> widget = widget.version_at 1.day.ago # the widget as it was one day ago
>> widget.save # reverted
Global enable/disable (useful in your tests)
# config/environments/test.rb
config.after_initialize do
PaperTrail.enabled = false
end
Invisible changes
- Thread-safety
- Cleaner module structure.
- Cleaner tests.
Finally
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.