Skip to content

Optional. Provides access to PaperTrail controller methods, like whodunnit

License

Notifications You must be signed in to change notification settings

paper-trail-gem/paper_trail-sinatra

Repository files navigation

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.

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:

  1. Add PaperTrail to your Gemfile.
gem 'paper_trail'
gem 'paper_trail-sinatra'
  1. Generate a migration to add a versions table to your database.

    bundle exec rake db:create_migration NAME=create_versions

  2. Copy contents of create_versions.rb into the create_versions migration that was generated into your db/migrate directory.

  3. Run the migration.

    bundle exec rake db:migrate

  4. Add has_paper_trail to the models you want to track.

PaperTrail provides some helper extensions that acts similar to the controller mixin it provides for Rails applications.

In your helpers you can override these methods:

# Returns the user who is responsible for any changes that occur.
# Defaults to current_user.
user_for_paper_trail

# Returns any information about the controller or request that you want
# PaperTrail to store alongside any changes that occur.
info_for_paper_trail

# Returns `true` (default) or `false` to turn PaperTrail on/off for per request.
paper_trail_enabled_for_request

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

About

Optional. Provides access to PaperTrail controller methods, like whodunnit

Resources

License

Stars

Watchers

Forks

Packages

No packages published