Giter Club home page Giter Club logo

paper_trail-sinatra's Introduction

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:

  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

Contributing

git clone
bundle
mkdir db
sqlite3 db/test.sqlite3
.read spec/create_db.sql
bundle exec rspec

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.