Auditable plugin

Plugin details

Auditable is an ActiveRecord extension that allows you to keep audit logs of any changes made to a model.

Websitehttp://www.mashd.cc/tag/auditable Repositorygit://github.com/jamesotron/Auditable.git Author James Harton Tags Audit, Rails, plugin, Logs, log LicenseUnknown

Documentation

Install the plugin:
ruby script/plugin install git://github.com/jamesotron/Auditable.git

Install using ./script/plugin:

# ./script/plugin install git://github.com/jamesotron/Auditable.git   
Initialized empty Git repository in /Users/jnh/tmp/test/vendor/plugins/Auditable/.git/
remote: Counting objects: 20, done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 20 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (20/20), done.
From git://github.com/jamesotron/Auditable
 * branch            HEAD       -> FETCH_HEAD
* Generating model and migration...
      exists  app/models/
      exists  test/unit/
      exists  test/fixtures/
      create  app/models/audit.rb
      create  test/unit/audit_test.rb
      create  test/fixtures/audits.yml
      create  db/migrate
      create  db/migrate/20091208021006_create_audits.rb
* Backing up existing model.rb
* Making model polymorphic...
* You probably want to run rake db:migrate now.
* Done.



Migrate your tables:

# rake db:migrate
(in /Users/jnh/tmp/test)
==  CreateAudits: migrating ===================================================
-- create_table(:audits)
   -> 0.0034s
==  CreateAudits: migrated (0.0040s) ==========================================



Add acts_as_auditable to your models:

class WorrisomeData < ActiveRecord::Base
  acts_as_auditable
end



Use your models as per normal, but all changes will be logged:

# ./script/console 
Loading development environment (Rails 2.3.5)
>> w = WorrisomeData.create(:secret => 'top secret string of doom')
=> #
>> w.secret 
=> "top secret string of doom"
>> w.secret = 'not so top secret string of doom'
=> "not so top secret string of doom"
>> w.save
=> true
>> puts w.audits.collect { |a| a.log } * "\n"
New WorrisomeData created by Unknown user.
	Current field values are:
		secret => "top secret string of doom"
		created_at => Tue Dec 08 02:14:41 UTC 2009
		updated_at => Tue Dec 08 02:14:41 UTC 2009
Instance WorrisomeData(1) saved by Unknown user.
	Current field values are:
		secret => "top secret string of doom"
		created_at => Tue Dec 08 02:14:41 UTC 2009
		updated_at => Tue Dec 08 02:14:41 UTC 2009
Instance WorrisomeData(1), field secret  accessed by Unknown user.
	Current field values are:
		secret => "top secret string of doom"
		created_at => Tue Dec 08 02:14:41 UTC 2009
		updated_at => Tue Dec 08 02:14:41 UTC 2009
Instance WorrisomeData(1) modified by Unknown user.
	Field secret changed from "top secret string of doom" to "not so top secret string of doom".
	Current field values are:
		secret => "top secret string of doom"
		created_at => Tue Dec 08 02:14:41 UTC 2009
		updated_at => Tue Dec 08 02:14:41 UTC 2009
Instance WorrisomeData(1) saved by Unknown user.
	Current field values are:
		secret => "not so top secret string of doom"
		created_at => Tue Dec 08 02:14:41 UTC 2009
		updated_at => Tue Dec 08 02:15:09 UTC 2009
=> nil

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: jamesotron, 8 months ago