Skip to content


Subversion checkout URL

You can clone with
Download ZIP
audits trails for crud and link tracking with analytics on charts
CSS Ruby HTML JavaScript
branch: master


Gem VersionBuild StatusCoverage StatusBitdeli Badge

It generates audit-trails for your rails application and provide analytics out of the box!

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.

Roughly it is doing similar to what Omniture/Google Analytics does, but it your data remain within your app, so you can build custom charts as and when you wish.


User visit & page view count by date range:



For rails 4.x+ & 3.2.6 + and ruby>1.9.2:

gem install audit_rails

or in application’s Gemfile add:

gem ‘audit_rails’


rails g audit_rails:install


To add audit migration:

rake audit_rails:install:migrations

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

Add attributes to migration generated from above rake task

Inherit from AuditRails::Audit:

# MyApp/app/models/audit.rb
class Audit < AuditRails::Audit
  # attr_accessible is only needed for Rails 3.2.6+ not needed for Rails 4+
  attr_accessible :action, :controller, :description, :user_name,
  # add associations as usual:
  belongs_to :book

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")

To see Analytics

Go to <app-url>/audit_rails/audits/analytics

To download the audit report as xls file:

Add this to initializers/mime_types.rb

Mime::Type.register "application/", :xls

Use below link in views:

link_to audit_rails.audits_path(:format => "xls")

To restrict access to analytics page

Restrict access to Analytics

What's next?

  • Rails 4+ support (Done: Tested with example application )
  • ReactJS awesomeness
  • geoip integration
  • World Map Integration



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!


This project rocks and uses MIT-LICENSE.

Something went wrong with that request. Please try again.