Giter Site home page Giter Site logo

ccabot / acts_as_audited Goto Github PK

View Code? Open in Web Editor NEW

This project forked from collectiveidea/audited

0.0 1.0 0.0 345 KB

acts_as_audited is an ActiveRecord extension that logs all changes to your models in an audits table.

Home Page: http://wiki.github.com/collectiveidea/acts_as_audited

License: MIT License

Ruby 100.00%

acts_as_audited's Introduction

acts_as_audited

acts_as_audited is an ActiveRecord extension that logs all changes to your models in an audits table, with optional revision comments.

Installation

In environment.rb:

Rails::Initializer.run do |config|
  ...
  config.gem 'acts_as_audited'
  ...
end

At your application root, run:

$ rake gems:install

Generate the migration:

  • If installing without a previous version of acts_as_audited or you do not mind overwriting your audits table:

    $ script/generate audited_migration add_audits_table
  • If upgrading from a version of acts_as_audited that does not contain comment functionality:

    $ script/generate audited_migration_update update_audits_table
  • After running one of the generators:

    $ rake db:migrate

Usage

Declare acts_as_audited on your models:

class User < ActiveRecord::Base
  acts_as_audited :except => [:password, :mistress]
end

Within a web request, will automatically record the user that made the change if your controller has a current_user method. Comments can be added to an audit by setting model.audit_comments before create/update/destroy. If the :comment_required option is given to acts_as_audited, the save/update/destroy action will fail with add an error on model.audit_comment and triggering a transaction rollback if model.audit_comment is nil.

To record a user in the audits outside of a web request, you can use as_user:

Audit.as_user(user) do
  # Perform changes on audited models
end

Caveats

If your model declares attr_accessible after acts_as_audited, you need to set :protect to false. acts_as_audited uses attr_protected internally to prevent malicious users from unassociating your audits, and Rails does not allow both attr_protected and attr_accessible. It will default to false if attr_accessible is called before acts_as_audited, but needs to be explicitly set if it is called after.

class User < ActiveRecord::Base
  acts_as_audited :protect => false
  attr_accessible :name
end

Compatability

acts_as_audited works with Rails 2.1 or later.

Getting Help

Join the mailing list for getting help or offering suggestions:

http://groups.google.com/group/acts_as_audited

Contributing

Contributions are always welcome. Checkout the latest code on GitHub:

http://github.com/collectiveidea/acts_as_audited

Please include tests with your patches. There are a few gems required to run the tests:

$ gem install multi_rails
$ gem install thoughtbot-shoulda jnunemaker-matchy --source http://gems.github.com

Make sure the tests pass against all versions of Rails since 2.1:

$ rake test:multi_rails:all

Please report bugs or feature suggestions on GitHub:

http://github.com/collectiveidea/acts_as_audited/issues

acts_as_audited's People

Contributors

airblade avatar bdegruyt avatar bkeepers avatar bryckbost avatar cainlevy avatar ccabot avatar ches avatar ckozus avatar danielmorrison avatar emfi avatar htanata avatar kennethkalmer avatar madadam avatar zorab47 avatar

Watchers

 avatar

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.