Browse, view, and revert changes to records in Ruby on Rails applications using the paper_trail gem.
- Ruby >= 3.1
- Rails >= 7.0, < 8.0
- PaperTrail >= 12.0
- A pagination library: will_paginate or Kaminari
Add to your Gemfile:
gem 'paper_trail_manager'If you don't already use a pagination library, add one:
gem 'kaminari'
# or
gem 'will_paginate'Install:
bundle installAdd the route to config/routes.rb:
resources :changes, controller: 'paper_trail_manager/changes'Restart your server and visit /changes to browse, view, and revert your changes.
A default stylesheet is included. Add to your layout or application CSS:
<%= stylesheet_link_tag 'paper_trail_manager/changes' %>Or require it in app/assets/stylesheets/application.css:
/*= require paper_trail_manager/changes */The styles are low-specificity and easy to override in your own stylesheet.
Create an initializer (e.g. config/initializers/paper_trail_manager.rb) to customize behavior.
Control access to the index, show, and revert actions independently:
# Control who can view the changes index
PaperTrailManager.allow_index_when do |controller|
controller.current_user.present?
end
# Control who can view individual change details (defaults to allow_index rules)
PaperTrailManager.allow_show_when do |controller, version|
controller.current_user&.admin? || version.whodunnit == controller.current_user&.id&.to_s
end
# Control who can revert changes
PaperTrailManager.allow_revert_when do |controller, version|
controller.current_user&.admin?
endNote: If you only call
allow_index_when, the same block is used as the default forallow_show_when. Callallow_show_whenseparately to override show authorization independently.
Configure how to look up users referenced in PaperTrail's whodunnit column:
PaperTrailManager.whodunnit_class = User
PaperTrailManager.whodunnit_name_method = :nicename # defaults to :nameSpecify a method to identify items on the index page:
PaperTrailManager.item_name_method = :nicenameCustomize (or disable) the user path helper:
PaperTrailManager.user_path_method = :admin_path # defaults to :user_path
PaperTrailManager.user_path_method = nil # no user linkThe index page defaults to 50 items per page. Override via query parameter:
/changes?per_page=25
When embedding PaperTrailManager inside another Rails engine:
PaperTrailManager.base_controller = "MyEngine::ApplicationController"
PaperTrailManager.route_helpers = MyEngine::Engine.routes.url_helpers
PaperTrailManager.layout = 'my_engine/application'Setup:
git clone https://github.com/DamageLabs/paper_trail_manager.git
cd paper_trail_manager
bundle installRunning tests:
appraisal rakeThe first run downloads gems for each Rails version in the test matrix, which may take a while.
Tests run against multiple combinations via Appraisal:
| Rails | PaperTrail | Pagination |
|---|---|---|
| 7.0 | 12.0 | kaminari, will_paginate |
| 7.0 | 15.0 | kaminari, will_paginate |
| 7.1 | 15.0 | kaminari, will_paginate |
CI runs each combination across Ruby 3.1, 3.2, and 3.3 (18 jobs total).
- Update the
Appraisalsfile with new version combinations - Run
appraisal generate && appraisal install - Fix any breaking changes
- Submit a pull request
- Security fix:
allow_show?now correctly delegates toallow_show_block(was incorrectly usingallow_index_block) - Bug fix: Gemspec
authorsfield was being overwritten byemail - Bug fix:
PER_PAGEconstant (50) now used as pagination default - CI: Dropped Rails 6.1 (incompatible with Ruby 3.1+), fixed Psych deserialization, added asset pipeline skip
- Tests: Added unit tests for authorization block delegation
- Modernized for Ruby 3.1–3.3 and Rails 7.0–7.1
See CHANGELOG.md for full history.
MIT — see LICENSE.txt for details.
This project was originally developed by Igal Koshevoy. Igal passed away on April 9th, 2013, and Tony Guntharp took over maintenance of the project.