Code Monkey home page Code Monkey logo

audit_rails's Introduction

AuditRails

<img src=“https://badge.fury.io/rb/audit_rails.png” alt=“Gem Version” />

An action based auditor, which has internal as well as outgoing link tracking.

It is inspired from many great audit gems in rails community that audits model and I was looking for a gem which can audit based on actions as well as can audit link tracking. This gem just serve this purpose.

Build Status

<img src=“https://travis-ci.org/gouravtiwari/audit_rails.png” />

Pre-requisites:

For rails 3.1.x and ruby 1.9.3:

gem install audit_rails

or in application’s Gemfile add:

gem ‘audit_rails’

Install

rails g audit_rails:install

Usage

To add audit migration:

rake audit_rails:install:migrations

Add audit.js to application.js file:

//= require audit_rails/audit

To add additional attributes to Audit (let’s say book_id):

  1. Add attributes to migration generated from above rake task

  2. Inherit from AuditRails::Audit:

    #MyApp/app/models/audit.rb
    class Audit < AuditRails::Audit
      attr_accessible :action, :controller, :description, :user_name, 
      :book_id
    
      #add associations as usual:
      belongs_to :book
    end
    

To log user events

Simply call ‘add_to_audit’ with desired parameters in any controller (as this is now a helper method included in application_controller.rb of application)

To override controller’s add_to_audit method (or the helper method)

Simply re-implement in application_controller.rb

To track user login (one per day)

Override current_user method in application controller, e.g.:

def current_user
  add_to_audit('login', 'sessions', "John Smith")
  super
end

To see all audits

Go to <app-url>/audit_rails/audits

To download the audit report as xls file:

* Add this to initializers/mime_types.rb
    Mime::Type.register "application/vnd.ms-excel", :xls

* Use below link in views:
    link_to audit_rails.audits_path(:format => "xls")

Changelog

github.com/gouravtiwari/audit_rails/blob/master/CHANGELOG.rdoc

Contribute

You are welcome to contribute and add more feature to this gem. I have added rspec and guard to it to run tests quickly. So running specs shouldn’t be a problem.

Please fork it, add specs and send a pull request!

License

This project rocks and uses MIT-LICENSE.

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.