PaperTrail::Sinatra
Register this module inside your Sinatra application to gain access to controller-level methods used by PaperTrail.
To configure PaperTrail for usage with Sinatra, your Sinatra app must be
using ActiveRecord 3, 4, or 5.
It is recommended to use the
Sinatra ActiveRecord Extension or something similar for managing your
application's ActiveRecord connection in a manner similar to the way Rails
does. If using the aforementioned Sinatra ActiveRecord Extension, steps for
setting up your app with PaperTrail will look something like this:
- Add PaperTrail to your
Gemfile.
gem 'paper_trail'
gem 'paper_trail-sinatra'
Generate a migration to add a
versionstable to your database.bundle exec rake db:create_migration NAME=create_versionsCopy contents of create_versions.rb into the
create_versionsmigration that was generated into yourdb/migratedirectory.Run the migration.
bundle exec rake db:migrateAdd
has_paper_trailto the models you want to track.
PaperTrail provides a helper extension that acts similar to the controller mixin
it provides for Rails applications.
It will set PaperTrail.whodunnit to whatever is returned by a method named
user_for_paper_trail which you can define inside your Sinatra Application. (by
default it attempts to invoke a method named current_user)
If you're using the modular Sinatra::Base style of application, you will
need to register the extension:
# bleh_app.rb
require 'sinatra/base'
class BlehApp < Sinatra::Base
register PaperTrail::Sinatra
end
Contributing
git clone
bundle
mkdir db
sqlite3 db/test.sqlite3
.read spec/create_db.sql
bundle exec rspec