Code Monkey home page Code Monkey logo

audited's Introduction

Audited Gem Version Build Status Code Climate Ruby Style Guide

Audited (previously acts_as_audited) is an ORM extension that logs all changes to your models. Audited can also record who made those changes, save comments and associate models related to the changes.

Audited currently (5.6) works with Rails 7.1, 7.0, 6.1, 6.0, 5.2.

For Rails 5.0 & 5.1, use gem version 5.4.3 For Rails 4, use gem version 4.x For Rails 3, use gem version 3.0 or see the 3.0-stable branch.

Supported Rubies

Audited supports and is tested against the following Ruby versions:

  • 2.3 (only tested on Sqlite due to testing issues with other DBs)
  • 2.4
  • 2.5
  • 2.6
  • 2.7
  • 3.0
  • 3.1
  • 3.2

Audited may work just fine with a Ruby version not listed above, but we can't guarantee that it will. If you'd like to maintain a Ruby that isn't listed, please let us know with a pull request.

Supported ORMs

Audited is currently ActiveRecord-only. In a previous life, Audited worked with MongoMapper. Use the 4.2-stable branch if you need MongoMapper.

Installation

Add the gem to your Gemfile:

gem "audited"

And if you're using require: false you must add initializers like this:

#./config/initializers/audited.rb
require "audited"

Audited::Railtie.initializers.each(&:run)

Then, from your Rails app directory, create the audits table:

$ rails generate audited:install
$ rake db:migrate

By default changes are stored in YAML format. If you're using PostgreSQL, then you can use rails generate audited:install --audited-changes-column-type jsonb (or json for MySQL 5.7+ and Rails 5+) to store audit changes natively with database JSON column types.

If you're using something other than integer primary keys (e.g. UUID) for your User model, then you can use rails generate audited:install --audited-user-id-column-type uuid to customize the audits table user_id column type.

Upgrading

If you're already using Audited (or acts_as_audited), your audits table may require additional columns. After every upgrade, please run:

$ rails generate audited:upgrade
$ rake db:migrate

Upgrading will only make changes if changes are needed.

Usage

Simply call audited on your models:

class User < ActiveRecord::Base
  audited
end

By default, whenever a user is created, updated or destroyed, a new audit is created.

user = User.create!(name: "Steve")
user.audits.count # => 1
user.update!(name: "Ryan")
user.audits.count # => 2
user.destroy
user.audits.count # => 3

Audits contain information regarding what action was taken on the model and what changes were made.

user.update!(name: "Ryan")
audit = user.audits.last
audit.action # => "update"
audit.audited_changes # => {"name"=>["Steve", "Ryan"]}

You can get previous versions of a record by index or date, or list all revisions.

user.revisions
user.revision(1)
user.revision_at(Date.parse("2016-01-01"))

Specifying columns

By default, a new audit is created for any attribute changes. You can, however, limit the columns to be considered.

class User < ActiveRecord::Base
  # All fields
  # audited

  # Single field
  # audited only: :name

  # Multiple fields
  # audited only: [:name, :address]

  # All except certain fields
  # audited except: :password
end

Specifying callbacks

By default, a new audit is created for any Create, Update, Touch (Rails 6+) or Destroy action. You can, however, limit the actions audited.

class User < ActiveRecord::Base
  # All fields and actions
  # audited

  # Single field, only audit Update and Destroy (not Create or Touch)
  # audited only: :name, on: [:update, :destroy]
end

You can ignore the default callbacks globally unless the callback action is specified in your model using the :on option. To configure default callback exclusion, put the following in an initializer file (config/initializers/audited.rb):

Audited.ignored_default_callbacks = [:create, :update] # ignore callbacks create and update

Comments

You can attach comments to each audit using an audit_comment attribute on your model.

user.update!(name: "Ryan", audit_comment: "Changing name, just because")
user.audits.last.comment # => "Changing name, just because"

You can optionally add the :comment_required option to your audited call to require comments for all audits.

class User < ActiveRecord::Base
  audited :comment_required => true
end

You can update an audit only if audit_comment is present. You can optionally add the :update_with_comment_only option set to false to your audited call to turn this behavior off for all audits.

class User < ActiveRecord::Base
  audited :update_with_comment_only => false
end

Limiting stored audits

You can limit the number of audits stored for your model. To configure limiting for all audited models, put the following in an initializer file (config/initializers/audited.rb):

Audited.max_audits = 10 # keep only 10 latest audits

or customize per model:

class User < ActiveRecord::Base
  audited max_audits: 2
end

Whenever an object is updated or destroyed, extra audits are combined with newer ones and the old ones are destroyed.

user = User.create!(name: "Steve")
user.audits.count # => 1
user.update!(name: "Ryan")
user.audits.count # => 2
user.destroy
user.audits.count # => 2

Current User Tracking

If you're using Audited in a Rails application, all audited changes made within a request will automatically be attributed to the current user. By default, Audited uses the current_user method in your controller.

class PostsController < ApplicationController
  def create
    current_user # => #<User name: "Steve">
    @post = Post.create(params[:post])
    @post.audits.last.user # => #<User name: "Steve">
  end
end

To use a method other than current_user, put the following in an initializer file (config/initializers/audited.rb):

Audited.current_user_method = :authenticated_user

Outside of a request, Audited can still record the user with the as_user method:

Audited.audit_class.as_user(User.find(1)) do
  post.update!(title: "Hello, world!")
end
post.audits.last.user # => #<User id: 1>

The standard Audited install assumes your User model has an integer primary key type. If this isn't true (e.g. you're using UUID primary keys), you'll need to create a migration to update the audits table user_id column type. (See Installation above for generator flags if you'd like to regenerate the install migration.)

Custom Audit User

You might need to use a custom auditor from time to time. This can be done by simply passing in a string:

class ApplicationController < ActionController::Base
  def authenticated_user
    if current_user
      current_user
    else
      'Alexander Fleming'
    end
  end
end

as_user also accepts a string, which can be useful for auditing updates made in a CLI environment:

Audited.audit_class.as_user("console-user-#{ENV['SSH_USER']}") do
  post.update_attributes!(title: "Hello, world!")
end
post.audits.last.user # => 'console-user-username'

If you want to set a specific user as the auditor of the commands in a CLI environment, whether that is a string or an ActiveRecord object, you can use the following command:

Audited.store[:audited_user] = "username"

# or

Audited.store[:audited_user] = User.find(1)

Associated Audits

Sometimes it's useful to associate an audit with a model other than the one being changed. For instance, given the following models:

class User < ActiveRecord::Base
  belongs_to :company
  audited
end

class Company < ActiveRecord::Base
  has_many :users
end

Every change to a user is audited, but what if you want to grab all of the audits of users belonging to a particular company? You can add the :associated_with option to your audited call:

class User < ActiveRecord::Base
  belongs_to :company
  audited associated_with: :company
end

class Company < ActiveRecord::Base
  audited
  has_many :users
  has_associated_audits
end

Now, when an audit is created for a user, that user's company is also saved alongside the audit. This makes it much easier (and faster) to access audits indirectly related to a company.

company = Company.create!(name: "Collective Idea")
user = company.users.create!(name: "Steve")
user.update!(name: "Steve Richert")
user.audits.last.associated # => #<Company name: "Collective Idea">
company.associated_audits.last.auditable # => #<User name: "Steve Richert">

You can access records' own audits and associated audits in one go:

company.own_and_associated_audits

Conditional auditing

If you want to audit only under specific conditions, you can provide conditional options (similar to ActiveModel callbacks) that will ensure your model is only audited for these conditions.

class User < ActiveRecord::Base
  audited if: :active?

  def active?
    last_login > 6.months.ago
  end
end

Just like in ActiveModel, you can use an inline Proc in your conditions:

class User < ActiveRecord::Base
  audited unless: Proc.new { |u| u.ninja? }
end

In the above case, the user will only be audited when User#ninja is false.

Disabling auditing

If you want to disable auditing temporarily doing certain tasks, there are a few methods available.

To disable auditing on a save:

@user.save_without_auditing

or:

@user.without_auditing do
  @user.save
end

To disable auditing on a column:

User.non_audited_columns = [:first_name, :last_name]

To disable auditing on an entire model:

User.auditing_enabled = false

To disable auditing on all models:

Audited.auditing_enabled = false

If you have auditing disabled by default on your model you can enable auditing temporarily.

User.auditing_enabled = false
@user.save_with_auditing

or:

User.auditing_enabled = false
@user.with_auditing do
  @user.save
end

Encrypted attributes

If you're using ActiveRecord's encryption (available from Rails 7) to encrypt some attributes, Audited will automatically filter values of these attributes. No additional configuration is required. Changes to encrypted attributes will be logged as [FILTERED].

class User < ActiveRecord::Base
  audited
  encrypts :password
end

Custom Audit model

If you want to extend or modify the audit model, create a new class that inherits from Audited::Audit:

class CustomAudit < Audited::Audit
  def some_custom_behavior
    "Hiya!"
  end
end

Then set it in an initializer:

# config/initializers/audited.rb

Audited.config do |config|
  config.audit_class = "CustomAudit"
end

Enum Storage

In 4.10, the default behavior for enums changed from storing the value synthesized by Rails to the value stored in the DB. You can restore the previous behavior by setting the store_synthesized_enums configuration value:

# config/initializers/audited.rb

Audited.store_synthesized_enums = true

Support

You can find documentation at: https://www.rubydoc.info/gems/audited

Or join the mailing list to get help or offer suggestions.

Contributing

In the spirit of free software, everyone is encouraged to help improve this project. Here are a few ways you can pitch in:

  • Use prerelease versions of Audited.
  • Report bugs.
  • Fix bugs and submit pull requests.
  • Write, clarify or fix documentation.
  • Refactor code.

audited's People

Contributors

bkeepers avatar bryckbost avatar bsiggelkow avatar ches avatar danielmorrison avatar dgm avatar domcleal avatar emfi avatar eric-hemasystems avatar ersatzryan avatar fatkodima avatar fivetwentysix avatar freemanoid avatar grosser avatar jaredbeck avatar jdufresne avatar jdurand avatar kennethkalmer avatar ksinkar avatar laserlemon avatar madadam avatar marcrohloff avatar mcyoung avatar miks avatar nicduke38degrees avatar nilakanta avatar tbrisker avatar tiagocassio avatar yknx4 avatar yuki24 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

audited's Issues

Is it rails3 ready?

I'm interested in this fork due to the comment requirement functionality.
Does this work with rails3?

Auditing of virtual attributes (e.g. tag_list)

I would like to audit virtual attributes, which are not stored as columns in the same table. Think about a “tag_list” managed by acts_as_taggable_on. This virtual attributes are stored elsewhere, but the changes should be audited in the owner model.

Perhaps this could be configured by an additional option like :add in addition to :except.

Any way to append onto the end of audit_changes?

I know that there is a comment field in the audits table but we are using that for something else.
We need a way to have that the password was changed without showing what it was/is now.
We were thinking of just appending on to the end of the audit_changes some text like "Password Changed".

undefined method `destroyed?' for #<Class:0x48e0edc>

activerecord (3.0.0) lib/active_record/base.rb:1016:in `method_missing'
activerecord (3.0.0) lib/active_record/associations/association_collection.rb:443:in `block in method_missing'
activerecord (3.0.0) lib/active_record/base.rb:1128:in `with_scope'
activerecord (3.0.0) lib/active_record/associations/association_proxy.rb:203:in `with_scope'
activerecord (3.0.0) lib/active_record/associations/association_collection.rb:439:in `method_missing'
activerecord (3.0.0) lib/active_record/autosave_association.rb:261:in `association_valid?'
activerecord (3.0.0) lib/active_record/autosave_association.rb:242:in `validate_single_association'
activerecord (3.0.0) lib/active_record/autosave_association.rb:180:in `block in add_autosave_association_callbacks'
activesupport (3.0.0) lib/active_support/callbacks.rb:414:in `_run_validate_callbacks'
activemodel (3.0.0) lib/active_model/validations.rb:212:in `run_validations!'
activemodel (3.0.0) lib/active_model/validations/callbacks.rb:67:in `block in run_validations!'
activesupport (3.0.0) lib/active_support/callbacks.rb:413:in `_run_validation_callbacks'
activemodel (3.0.0) lib/active_model/validations/callbacks.rb:67:in `run_validations!'
activemodel (3.0.0) lib/active_model/validations.rb:179:in `valid?'
activerecord (3.0.0) lib/active_record/validations.rb:55:in `valid?'
activerecord (3.0.0) lib/active_record/validations.rb:75:in `perform_validations'
activerecord (3.0.0) lib/active_record/validations.rb:43:in `save'
activerecord (3.0.0) lib/active_record/attribute_methods/dirty.rb:21:in `save'
activerecord (3.0.0) lib/active_record/transactions.rb:237:in `block (2 levels) in save'
activerecord (3.0.0) lib/active_record/transactions.rb:289:in `block in with_transaction_returning_status'
activerecord (3.0.0) lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
activerecord (3.0.0) lib/active_record/transactions.rb:204:in `transaction'
activerecord (3.0.0) lib/active_record/transactions.rb:287:in `with_transaction_returning_status'
activerecord (3.0.0) lib/active_record/transactions.rb:237:in `block in save'
activerecord (3.0.0) lib/active_record/transactions.rb:248:in `rollback_active_record_state!'
activerecord (3.0.0) lib/active_record/transactions.rb:236:in `save'
active_scaffold (3.0.12) lib/extensions/unsaved_record.rb:15:in `save_with_unsaved_flag'
activerecord (3.0.0) lib/active_record/associations/has_many_association.rb:66:in `insert_record'
activerecord (3.0.0) lib/active_record/associations/association_collection.rb:136:in `block (3 levels) in <<'
activerecord (3.0.0) lib/active_record/associations/association_collection.rb:479:in `add_record_to_target_with_callbacks'
activerecord (3.0.0) lib/active_record/associations/association_collection.rb:135:in `block (2 levels) in <<'
activerecord (3.0.0) lib/active_record/associations/association_collection.rb:133:in `each'
activerecord (3.0.0) lib/active_record/associations/association_collection.rb:133:in `block in <<'
activerecord (3.0.0) lib/active_record/associations/association_collection.rb:158:in `block in transaction'
activerecord (3.0.0) lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
activerecord (3.0.0) lib/active_record/transactions.rb:204:in `transaction'
activerecord (3.0.0) lib/active_record/associations/association_collection.rb:157:in `transaction'
activerecord (3.0.0) lib/active_record/associations/association_collection.rb:132:in `<<'
app/models/book_job.rb:27:in `block in initialize_updates'

Am getting the above error in Rails 3.0.0 and 3.0.3 also.

I am unable to use this gem with jruby 1.6.0.RC1

I tried to bundle "acts_as_audited", "2.0.0.rc5" with jruby 1.6.0.RC1 but I am unable to do it

I tried to bundle "acts_as_audited", "2.0.0.rc3", :git => "git://github.com/collectiveidea/acts_as_audited.git", :tag => "2.0.0.rc3", it worked well on my development. But when I create a war file and tried to run on a jvm, I am stuck that I can't do bundle install with war file.

Is there any other way that I can use this gem on my jruby application :(

Thank you Kenneth for such a cool and nice gem!!

Problem with changes hash

I would appreciate any advice that can be offered for this strange (to me, at least) problem. I'm not sure if this is a problem with a_a_a or with something I'm doing. As far as I know, I'm not overriding any YAML methods, and I have these two lines in my config/environments/production.rb:

config.cache_classes = true
config.action_controller.perform_caching = true

I'm using acts_as_audited (1.1.0) in a Rails 2.3.5 app.

I just created a comment (model Comment, polymorphic) and updated it. In the Rails console, I can find the audit record, but I cannot explicity show the changes until I explicity deserialize (using y). Does this make sense? I've pasted an example below. Note the empty hash that results from "a.changes". Also, is it strange that the value to the "created_on" key in the changes hash is not an array, but rather a single DateTime?

-cal

>> a = Audit.find 209881
Audit Load (0.4ms)  SELECT * FROM `audits` WHERE (`audits`.`id` = 209881) 
=> #<Audit id: 209881, auditable_id: 3592, auditable_type: "Comment", user_id: 1,    user_type: "User", username: nil, action: "create", changes: {"created_on"=>Fri Apr 02 14:00:11 -0400 2010, "commentable_type"=>"Collection", "commentable_id"=>1415, "text"=>"<p>test</p>", "updated_on"=>Fri Apr 02 14:00:11 -0400 2010, "created_by"=>1, "updated_by"=>1}, version: 1, created_at: "2010-04-02 14:00:11">
>> a.changes
=> {}
>> y a
--- !ruby/object:Audit 
attributes: 
  created_at: 2010-04-02 14:00:11
  action: create
  username: 
  user_type: User
  id: "209881"
  version: "1"
  user_id: "1"
  auditable_type: Comment
  changes: 
    created_on: &id001 2010-04-02 14:00:11.256183 -04:00
    commentable_type: Collection
    commentable_id: 1415
    text: <p>test</p>
    updated_on: *id001
    created_by: 1
    updated_by: 1
  auditable_id: "3592"
attributes_cache: {}

changed_attributes: {}

=> nil
>> a.changes
=> {"created_on"=>Fri Apr 02 14:00:11 -0400 2010, "commentable_type"=>"Collection", "commentable_id"=>1415, "text"=>"<p>test</p>", "updated_on"=>Fri Apr 02 14:00:11 -0400 2010, "created_by"=>1, "updated_by"=>1}

Changes in audit selects not serialized on rails server start.

Hey there!
Thanks for this most excellent plugin!

The bug/issue I seem to have found is: When I start up a rails application, and immediately select a few audits (without creating any new audits), the deserialization of 'changes' returns an empty hash. Here's some sample output from the debugger (reformatted for readability):

(rdb:4) @unsent_changes.size
4

(rdb:4) @unsent_changes[0]  
#<AuditE911 id: 25, 
            auditable_id: 2020, 
            auditable_type: "MasterRelation", 
            user_id: 8, 
            user_type: "User", 
            username: nil, 
            action: "create", 
            changes: {"extension"=>nil, 
                      "phone_id"=>nil, 
                      "employee_id"=>1124, 
                      "location_id"=>2131, 
                      "used_for_411"=>nil}, 
            version: 1, 
            created_at: "2009-06-11 21:43:40",
            sent: false
>
(rdb:4) @unsent_changes[0].changes
{}

(rdb:4) MasterRelation.create!(:employee_id => 1)       
#<MasterRelation ...

(rdb:4) @unsent_changes[0].changes
{"extension"=>nil, 
 "phone_id"=>nil, 
 "employee_id"=>1124, 
 "location_id"=>2131, 
 "used_for_411"=>nil}

It appears everything works well, but getting that initial change select is really eluding me.

Audit record has no user on first request posted to a server

This happens in an app that uses acts_as_audited and relies on controller.current_user to provide the user to the Audit record. Steps to reproduce:

  1. start the server
  2. navigate to an edit form for an audited model
  3. re-start the server
  4. post the form

The audit record has no user.

This is happening because on line 28 of audit_sweeper.rb, the controller is nil.

The reason controller is nil is that the before hook on line 8 in action_controller/caching/sweeper.rb, which assigns the current controller to the @controller instance variable, is not called on the first request.

We were able to work around this issue in our app with the following addition to our ApplicationController.

require 'acts_as_audited/audit'
require 'acts_as_audited/audit_sweeper'
cache_sweeper :audit_sweeper, :only => [:create, :update, :destroy]

VERSIONS:

rails-2.3.5
acts_as_audited-1.1.1
ree-1.8.7-2010.01

Working with remote DB

I have audits table on a local (to rails) server and the rest of tables are located on a remote server.
I get "NoMethodError (undefined method `controller_name' for nil:NilClass)" every time I try to save or delete any record. I'm using :only => [...] param, because otherwise I get that error on every request to any resource.

Removing audit from the application controller stops the error message to appear.

cannot audit when an association is lost

From what I can tell, the associated audits are only associated with the "new" association. That means, if you change an association, you can't get a complete history of association changes on a model which has_many something.

I think it's a limitation in the data model, but as I'm new to this project, is there a reason that both the new and old association aren't being stored in an audit? Or do you have any ideas of how that would work?

Hopefully this example will explain better what I mean.

class Person
  belongs_to :house
end

class House 
  has_many :persons
end

h1 = House.create
h2 = House.create

p1 = Person.create(:house => h1)
p2 = Person.create(:house => h2)

p1.audits # => [Audit #1]
h1.associated_audits # => [Audit #1]

p2.audits # => [Audit #2]
h2.associated_audits # => [Audit #2]

p2.house = h1

p2.audits # => [Audit #2, Audit #3]
h1.associated_audits # => [Audit #1, Audit #3]

# everything as expected up until here:
h2.associated_audits # => [Audit #2]

# I expected (hoped for) something like this
h2.associated_audits # => [Audit #2, Audit #3]

Please let me know if there's already a way to obtain this information, or if there's a good reason that you can't.

AddAssociationToAudits problem when upgrading the gem

I upgraded my application from rails 2 to rails 3.0.3 and when i run the upgrade migrations generated by acts_as_audited gem, i get the following error.

== AddAssociationToAudits: migrating =========================================
-- add_column(:audits, :association_id, :integer, {})
-> 0.0014s
-- add_foreign_key(:audits, :association_id, "associations", :id, {})
rake aborted!
An error has occurred, this and all later migrations canceled:

PGError: ERROR: relation "associations" does not exist
: ALTER TABLE audits ADD FOREIGN KEY (association_id) REFERENCES associations (id) DEFERRABLE

The first 3 migrations ran successfully.
== AddCommentToAudits: migrating =============================================
-- add_column(:audits, :comment, :string, {})
-> 0.0930s
== AddCommentToAudits: migrated (0.0961s) ====================================

== RenameChangesToAuditedChanges: migrating ==================================
-- rename_column(:audits, :changes, :audited_changes)
-> 0.0011s
== RenameChangesToAuditedChanges: migrated (0.0019s) =========================

== AddRemoteAddressToAudits: migrating =======================================
-- add_column(:audits, :remote_address, :string, {})
-> 0.0012s
== AddRemoteAddressToAudits: migrated (0.0017s) ==============================

Thanks

Duplicate Audits

When there are two separate controllers that audit a model, there are duplicate audits created when class caching is enabled. For example:

class PostsController < ApplicationController
  audit Post, :only => :create
  ...
end

class AdminController < ApplicationController
  audit Post
  ...
end

"Stack level too deep" on Rails 3.1.rc1

I've used acts_as_audited with rails 3.0 successfully. Trying to convert the project to rails 3.1 I get "stack level too deep" error any time Audit object is saved.
How to reproduce:

  1. Create new project.
  2. Add acts_as_audited.
  3. Enter rails console and run Audit.create:
Loading development environment (Rails 3.1.0.rc1)
 :001 > Audit.create
   (0.1ms)  SELECT MAX("audits"."version") AS max_id FROM "audits" WHERE "audits"."auditable_id" IS NULL AND "audits"."auditable_type" IS NULL
SystemStackError: stack level too deep
    from /home/ineu/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/workspace.rb:80
Maybe IRB bug!!

JRuby 1.6.0.RC1 Rails 3.0.3 Glassfish Deployment

Hey Kenneth sorry to bother you again with Jruby and stuff.

I am able to deploy by auditing my model using acts_as_audited 2.0.0.rc5
gem on Webrick successfully.

But when I do a war and try to deploy the war file on glassfish, I am
stuck with following errors. I didnt find much about this on google and
even tried all the things I found there

The occured error is like this. Can anyone please help me out

[#|2011-02-09T14:08:02.558-0600|SEVERE|glassfish3.0.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=32;_ThreadName=http-thread-pool-8080-(1);|WebModule[/gavel]Application
Error
org.jruby.rack.RackInitializationException: undefined method
cache_sweeper' for ActionController::Base:Class from /home/dev2/.rvm/gems/jruby-1.6.0.RC1@global/bundler/gems/acts_as_audited-ccc7043d113f/lib/acts_as_audited.rb:44:in class_eval'
from
/home/dev2/.rvm/gems/jruby-1.6.0.RC1@global/bundler/gems/acts_as_audited-ccc7043d113f/lib/acts_as_audited.rb:44
from
/home/dev2/.rvm/gems/jruby-1.6.0.RC1@global/bundler/gems/acts_as_audited-ccc7043d113f/lib/acts_as_audited.rb:68:in
require' from /home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in require'
from
/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in
each' from /home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in require'
from
/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in
each' from /home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in require'
... 20 levels...
from classpath:/vendor/rack-1.2.1/rack/builder.rb:46:in initialize' from <web.xml>:1:innew'
from <web.xml>:1

at
org.jruby.rack.DefaultRackApplicationFactory$4.init(DefaultRackApplicationFactory.java:198)
at
org.jruby.rack.DefaultRackApplicationFactory.getApplication(DefaultRackApplicationFactory.java:61)
at
org.jruby.rack.PoolingRackApplicationFactory.getApplication(PoolingRackApplicationFactory.java:94)
at
org.jruby.rack.DefaultRackDispatcher.process(DefaultRackDispatcher.java:28)
at org.jruby.rack.RackFilter.doFilter(RackFilter.java:63)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
at
com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
at
org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
at
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:239)
at
com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
at
com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
at
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
at
com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
at
com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
at
com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
at
com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at
com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at
com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.jruby.exceptions.RaiseException: undefined method
`cache_sweeper' for ActionController::Base:Class
at
Kernel.cache_sweeper(/home/dev2/.rvm/gems/jruby-1.6.0.RC1@global/bundler/gems/acts_as_audited-ccc7043d113f/lib/acts_as_audited.rb:45)
at
(unknown).(unknown)(/home/dev2/.rvm/gems/jruby-1.6.0.RC1@global/bundler/gems/acts_as_audited-ccc7043d113f/lib/acts_as_audited.rb:44)
at
Module.class_eval(/home/dev2/.rvm/gems/jruby-1.6.0.RC1@global/bundler/gems/acts_as_audited-ccc7043d113f/lib/acts_as_audited.rb:44)
at
Module.class_eval(/home/dev2/.rvm/gems/jruby-1.6.0.RC1@global/bundler/gems/acts_as_audited-ccc7043d113f/lib/acts_as_audited.rb:44)
at
(unknown).(unknown)(/home/dev2/.rvm/gems/jruby-1.6.0.RC1@global/bundler/gems/acts_as_audited-ccc7043d113f/lib/acts_as_audited.rb:68)
at

Class:01x1d362c1.require(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:68)

at
Bundler::Runtime.require(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:66)
at
Array.each(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:66)
at
Bundler::Runtime.require(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:55)
at
Array.each(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:55)
at
Bundler::Runtime.require(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler.rb:120)
at

Class:01x1fc79cc.require(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/config/application.rb:7)

at
(unknown).(unknown)(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/config/application.rb:239)
at
Kernel.require(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239)
at
ActiveSupport::Dependencies::Loadable.require(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225)
at
ActiveSupport::Dependencies::Loadable.load_dependency(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596)
at
ActiveSupport::Dependencies.new_constants_in(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225)
at
ActiveSupport::Dependencies::Loadable.load_dependency(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239)
at
ActiveSupport::Dependencies::Loadable.require(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/config/environment.rb:2)
at
(unknown).(unknown)(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/config/environment.rb:239)
at
Kernel.require(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239)
at
ActiveSupport::Dependencies::Loadable.require(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225)
at
ActiveSupport::Dependencies::Loadable.load_dependency(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596)
at
ActiveSupport::Dependencies.new_constants_in(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225)
at
ActiveSupport::Dependencies::Loadable.load_dependency(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/activesupport-3.0.3/lib/active_support/depende[#|2011-02-09T14:08:02.558-0600|SEVERE|glassfish3.0.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=32;_ThreadName=Thread-1;|WebModule[/gavel]Application
Error
org.jruby.rack.RackInitializationException: undefined method
cache_sweeper' for ActionController::Base:Class from /home/dev2/.rvm/gems/jruby-1.6.0.RC1@global/bundler/gems/acts_as_audited-ccc7043d113f/lib/acts_as_audited.rb:44:in class_eval'
from
/home/dev2/.rvm/gems/jruby-1.6.0.RC1@global/bundler/gems/acts_as_audited-ccc7043d113f/lib/acts_as_audited.rb:44
from
/home/dev2/.rvm/gems/jruby-1.6.0.RC1@global/bundler/gems/acts_as_audited-ccc7043d113f/lib/acts_as_audited.rb:68:in
require' from /home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in require'
from
/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in
each' from /home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in require'
from
/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in
each' from /home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in require'
... 20 levels...
from classpath:/vendor/rack-1.2.1/rack/builder.rb:46:in initialize' from <web.xml>:1:innew'
from <web.xml>:1

at
org.jruby.rack.DefaultRackApplicationFactory$4.init(DefaultRackApplicationFactory.java:198)
at
org.jruby.rack.DefaultRackApplicationFactory.getApplication(DefaultRackApplicationFactory.java:61)
at
org.jruby.rack.PoolingRackApplicationFactory.getApplication(PoolingRackApplicationFactory.java:94)
at
org.jruby.rack.DefaultRackDispatcher.process(DefaultRackDispatcher.java:28)
at org.jruby.rack.RackFilter.doFilter(RackFilter.java:63)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
at
com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
at
org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
at
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:239)
at
com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
at
com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
at
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
at
com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
at
com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
at
com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
at
com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at
com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at
com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.jruby.exceptions.RaiseException: undefined method
`cache_sweeper' for ActionController::Base:Class
at
Kernel.cache_sweeper(/home/dev2/.rvm/gems/jruby-1.6.0.RC1@global/bundler/gems/acts_as_audited-ccc7043d113f/lib/acts_as_audited.rb:45)
at
(unknown).(unknown)(/home/dev2/.rvm/gems/jruby-1.6.0.RC1@global/bundler/gems/acts_as_audited-ccc7043d113f/lib/acts_as_audited.rb:44)
at
Module.class_eval(/home/dev2/.rvm/gems/jruby-1.6.0.RC1@global/bundler/gems/acts_as_audited-ccc7043d113f/lib/acts_as_audited.rb:44)
at
Module.class_eval(/home/dev2/.rvm/gems/jruby-1.6.0.RC1@global/bundler/gems/acts_as_audited-ccc7043d113f/lib/acts_as_audited.rb:44)
at
(unknown).(unknown)(/home/dev2/.rvm/gems/jruby-1.6.0.RC1@global/bundler/gems/acts_as_audited-ccc7043d113f/lib/acts_as_audited.rb:68)
at

Class:01x1d362c1.require(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:68)

at
Bundler::Runtime.require(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:66)
at
Array.each(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:66)
at
Bundler::Runtime.require(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:55)
at
Array.each(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:55)
at
Bundler::Runtime.require(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler.rb:120)
at

Class:01x1fc79cc.require(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/config/application.rb:7)

at
(unknown).(unknown)(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/config/application.rb:239)
at
Kernel.require(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239)
at
ActiveSupport::Dependencies::Loadable.require(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225)
at
ActiveSupport::Dependencies::Loadable.load_dependency(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596)
at
ActiveSupport::Dependencies.new_constants_in(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225)
at
ActiveSupport::Dependencies::Loadable.load_dependency(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239)
at
ActiveSupport::Dependencies::Loadable.require(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/config/environment.rb:2)
at
(unknown).(unknown)(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/config/environment.rb:239)
at
Kernel.require(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239)
at
ActiveSupport::Dependencies::Loadable.require(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225)
at
ActiveSupport::Dependencies::Loadable.load_dependency(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596)
at
ActiveSupport::Dependencies.new_constants_in(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225)
at
ActiveSupport::Dependencies::Loadable.load_dependency(/home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239)
at
ActiveSupport::Dependencies::Loadable.require(classpath:/jruby/rack/rails.rb:169)
at
JRuby::Rack::RailsBooter::Rails3Environment.load_environment(classpath:/jruby/rack/rails.rb:173)
at
JRuby::Rack::RailsBooter::Rails3Environment.to_app(classpath:/jruby/rack/rails.rb:194)
at #Class:01x11a2567.new(<web.xml>:1)
at
(unknown).(unknown)(classpath:/vendor/rack-1.2.1/rack/builder.rb:46)
at
Kernel.instance_eval(classpath:/vendor/rack-1.2.1/rack/builder.rb:46)
at
Kernel.instance_eval(classpath:/vendor/rack-1.2.1/rack/builder.rb:46)
at Rack::Builder.initialize(<web.xml>:1)
at (unknown).new(<web.xml>:1)
at (unknown).(unknown)(:1)
|#]

ncies.rb:239)
at
ActiveSupport::Dependencies::Loadable.require(classpath:/jruby/rack/rails.rb:169)
at
JRuby::Rack::RailsBooter::Rails3Environment.load_environment(classpath:/jruby/rack/rails.rb:173)
at
JRuby::Rack::RailsBooter::Rails3Environment.to_app(classpath:/jruby/rack/rails.rb:194)
at #Class:01x11a2567.new(<web.xml>:1)
at
(unknown).(unknown)(classpath:/vendor/rack-1.2.1/rack/builder.rb:46)
at
Kernel.instance_eval(classpath:/vendor/rack-1.2.1/rack/builder.rb:46)
at
Kernel.instance_eval(classpath:/vendor/rack-1.2.1/rack/builder.rb:46)
at Rack::Builder.initialize(<web.xml>:1)
at (unknown).new(<web.xml>:1)
at (unknown).(unknown)(:1)
|#]

Does not support HABTM relationships

I am really loving this gem and in the process of doing a full integration into a Rails 2.x app.

Unfortunately acts_as_audited does not have any way to track changes in many to many relationships, specifically has-and-belongs-to-many (HABTM).

In these cases the only data representing the relationship is in a join table with no actual model. The only way I can think of to implement acts_as_audited would be to change HABTM to has_many :through, so there is an actual model to track. However even this is not ideal.

If I am missing something please let me know. I'm really loving the implementation but not sure how to proceed withthis.

Stack level too deep in User model with authlogic

When I try to audit my Users model I get a stack level too deep (see below).

My application_controller looks like this:

 class ApplicationController < ActionController::Base
 protect_from_forgery # See ActionController::RequestForgeryProtection for details
   helper :layout

   audit Agent, AgentSite, AlertOption, Bot, Channel, Client, Listing, Note, Recipient, Site, Type

   filter_parameter_logging :password, :password_confirmation
   helper_method :current_user_session, :current_user

   def load_flash
     render :partial => "layouts/flash"
   end

   protected

   def current_user
     return @current_user if defined?(@current_user)
     @current_user = current_user_session && current_user_session.user
   end

   def store_location
     session[:return_to] = request.request_uri
   end

   private

   def current_user_session
     return @current_user_session if defined?(@current_user_session)
     @current_user_session = UserSession.find
   end

end

stack level too deep RAILS_ROOT: /Users/jlippiner/Projects/repuguard

Application Trace | Framework Trace | Full Trace
/Users/jlippiner/.rvm/gems/ruby-1.9.1-p378+rg/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in retrieve_connection_pool' /Users/jlippiner/.rvm/gems/ruby-1.9.1-p378+rg/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:inretrieve_connection'
/Users/jlippiner/.rvm/gems/ruby-1.9.1-p378+rg/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:123:in retrieve_connection' /Users/jlippiner/.rvm/gems/ruby-1.9.1-p378+rg/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:115:inconnection'
/Users/jlippiner/.rvm/gems/ruby-1.9.1-p378+rg/gems/activerecord-2.3.5/lib/active_record/base.rb:3113:in quoted_table_name' /Users/jlippiner/.rvm/gems/ruby-1.9.1-p378+rg/gems/activerecord-2.3.5/lib/active_record/base.rb:1684:inconstruct_finder_sql'
/Users/jlippiner/.rvm/gems/ruby-1.9.1-p378+rg/gems/activerecord-2.3.5/lib/active_record/base.rb:1548:in find_every' /Users/jlippiner/.rvm/gems/ruby-1.9.1-p378+rg/gems/activerecord-2.3.5/lib/active_record/base.rb:1505:infind_initial'
/Users/jlippiner/.rvm/gems/ruby-1.9.1-p378+rg/gems/activerecord-2.3.5/lib/active_record/base.rb:613:in find' /Users/jlippiner/.rvm/gems/ruby-1.9.1-p378+rg/gems/activerecord-2.3.5/lib/active_record/base.rb:1900:infind_by_id'
/Users/jlippiner/Projects/repuguard/vendor/gems/authlogic-2.1.2/lib/authlogic/session/scopes.rb:95:in block in search_for_record' /Users/jlippiner/.rvm/gems/ruby-1.9.1-p378+rg/gems/activerecord-2.3.5/lib/active_record/base.rb:2143:inwith_scope'
/Users/jlippiner/Projects/repuguard/vendor/gems/authlogic-2.1.2/lib/authlogic/session/scopes.rb:94:in search_for_record' /Users/jlippiner/Projects/repuguard/vendor/gems/authlogic-2.1.2/lib/authlogic/session/cookies.rb:108:inpersist_by_cookie'
/Users/jlippiner/.rvm/gems/ruby-1.9.1-p378+rg/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:178:in evaluate_method' /Users/jlippiner/.rvm/gems/ruby-1.9.1-p378+rg/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:166:incall'
/Users/jlippiner/.rvm/gems/ruby-1.9.1-p378+rg/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:93:in block in run' /Users/jlippiner/.rvm/gems/ruby-1.9.1-p378+rg/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:92:ineach'
/Users/jlippiner/.rvm/gems/ruby-1.9.1-p378+rg/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:92:in run' /Users/jlippiner/.rvm/gems/ruby-1.9.1-p378+rg/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:276:inrun_callbacks'
/Users/jlippiner/Projects/repuguard/vendor/gems/authlogic-2.1.2/lib/authlogic/session/callbacks.rb:79:in persist' /Users/jlippiner/Projects/repuguard/vendor/gems/authlogic-2.1.2/lib/authlogic/session/persistence.rb:55:inpersisting?'
/Users/jlippiner/Projects/repuguard/vendor/gems/authlogic-2.1.2/lib/authlogic/session/persistence.rb:39:in find' /Users/jlippiner/Projects/repuguard/app/controllers/application_controller.rb:30:incurrent_user_session'
/Users/jlippiner/Projects/repuguard/app/controllers/application_controller.rb:19:in current_user' /Users/jlippiner/Projects/repuguard/app/controllers/application_controller.rb:30:incurrent_user_session'
/Users/jlippiner/Projects/repuguard/app/controllers/application_controller.rb:19:in current_user' /Users/jlippiner/Projects/repuguard/app/controllers/application_controller.rb:30:incurrent_user_session'
/Users/jlippiner/Projects/repuguard/app/controllers/application_controller.rb:19:in current_user' /Users/jlippiner/Projects/repuguard/app/controllers/application_controller.rb:30:incurrent_user_session'
/Users/jlippiner/Projects/repuguard/app/controllers/application_controller.rb:19:in current_user' /Users/jlippiner/Projects/repuguard/app/controllers/application_controller.rb:30:incurrent_user_session'
/Users/jlippiner/Projects/repuguard/app/controllers/application_controller.rb:19:in current_user' /Users/jlippiner/Projects/repuguard/app/controllers/application_controller.rb:30:incurrent_user_session'
/Users/jlippiner/Projects/repuguard/app/controllers/application_controller.rb:19:in `current_user'

example has_many :changes conflicts with ActiveRecord::Dirty

It's not a big deal, but it could be confusing for people trying to figure things out.
The example in the wiki suggests:

has_many :changes, :class_name => 'Audit', :as => :user

however that conflicts with ActiveRecord::Dirty's changes method that provides the list of changes to an AR object.

created_at field not being recorded

When looking at the audit table, the created_at values are all:

0000-00-00 00:00:00

Is there something needed to get this working?

I am using Rails 3.0.10 with MySQL

audited_changes are not stored

I managed to install acts_as_audited 2.0.0.rc3 on rails3 sample app. Changes to the model are recorded, but the audited_changes column stays empty. Do I have to change something more?

kennethkalmer about 2 hours ago | link @zettworks, no, can you check against 2.0.0.rc4 (now on rubygems) and open a bug with some re-produceable steps that I can follow (if needed) ?

@kennethkalmer: Now I have 2.0.0.rc5 installed.

Still the same problem. Most data fields are filled, but the most interesting 'audited_changes' have just a '---' entry. I would expect that it stores what has been changed?
I'm quite new to Rails, which files or information would be need to describe the problem
appropriately or in 're-producable' way.

I

auditable_type is set to 'Application' instead of model_class.constantize

I'm testing the acts_as_audited gem (v2.0.0.rc7) on a demo application. A few of my model classes are descendants of Application. I noticed the audit record uses 'Application' instead of my model class constantized name. I tried to change this myself, but I cannot find where auditable_type is set within the gem. Below is an example audit record:

=> #<Audit id: 17, auditable_id: 648, auditable_type: "Application", association_id: nil, association_type: nil, user_id: 3, user_type: "User", username: nil, action: "update", audited_changes: {"quantity"=>[1, 2]}, version: 2, comment: nil, remote_address: "127.0.0.1", created_at: "2011-02-27 12:13:50"> 

I would have expected auditable_type to be 'LineItem' instead of 'Application'. Is the above behavior correct?

:only => [:update, :destroy] not working

In my application controller I have something like
audit Model1, Model2, Model3, :only => [:update, :destroy]
However, all three actions are being audited.
Looking at the code it appears that the :only option is treated in two different ways. In the acts_as_audited method, :only is used to modify the attribute list (not the actions). However in the controller/sweepers creation audit method, the :only option (and any others) is passed on to the sweepers. So, I'm not sure which way you intended this to go. It feels a little odd to have :only and :except do two totally different things, so would another option (:action?) be in order? Any other ideas or am I reading this wrong?
Rails 2.3.2
Thanks for your help!

Gem is missing

There is a gemspec in repository, but gem is not being generated by github

Can you check whether methods exist before creating them?

Hello,

When adding methods to another class, like the methods you add to models, can you first check whether such methods do exists and throw an exception if they do. I added auditing to a project which had some relationships called versions and it started behaving bad in very weird ways.

I think it's a good metaprogramming practice to always check for the existence of methods before adding them.

Thanks.

It's not possible to get at version 0 (i.e. before any changes) of an object.

Say I have an object and I start to audit it. If I save a change to the object then an audit record is created. I can see that I have one revision of the object, and the audit record knows what the field used to be before the change, but there's no way for me to get a version of the object as it looked before that change.

Viewing subsequent revisions is fine; it's just with the initial one that we have this problem.

Audit.order not working as expected

I had trouble writing a view for audits, the records wouldn't sort chronologically, so I tried:

ruby-1.9.2-p0 > Audit.order("ID DESC").all.each{|a| puts a.id  }
10025
10024
10023
10020
10002
10000
10021
10001
10022

Then I tried to_sql and got surprised:

ruby-1.9.2-p0 > Audit.order("ID DESC").to_sql
 => "SELECT \"AUDITS\".* FROM \"AUDITS\" ORDER BY version, ID DESC" 

Is there a workaround over this issue?

Best regards,

Borna

Audit.changes and Model.revision[#] inconsistent

I have an employee model using acts_as_audited. When I first create the employee, the corresponding audit data and the employee revision data are congruent. However, I do not get what I expect when reviewing the audit and revision data when I do something like this:

@employee.email = "[email protected]"
@employee.save

I should expect that my first revision should contain the original piece of data I entered for the employee's email address. Instead I see the very first revision of the employee with the updated email address like so:

@employee.revision(0)
=> Employee id: 1, email: "[email protected]", active: true

When I view my audit data, audit[#].changes displays the correct change for the model.

@Audits[0].changes
=> "--- email: [email protected]"

and

@Audits[1].changes
=> {"email"=>["[email protected]", "[email protected]"]}

So the question arises. Why doesn't @employee.revisions reflect @Audits[#].changes?

Internal Server error 500

In my application i am obtaining an error 500 (Internal Server Error) and this is produced by this plugin. If I comment the audit in my model, then all runs perfectly. Any suggestions?

Schema changes issue when using object.revisions

Say I have the following process:

  1. I have a table with fields A and B.
  2. An object O is created using this "schema".
  3. I alter the table by adding a new field C.
  4. I update O with a value for C.

Ok, when I have a look at O.audits.changes at the step where I give a value for C, I get:
'null' => 'my_value_for_C'. (value at version 1 => value at version 2 )
That looks alright.

Now, when I use:
O.revisions.each do |revision|
puts "Version #{revision.version}: #{revision.c}"
end

I get something like:
Version 1: 'my_value_for_C'
Version 2: 'my_value_for_C'

Instead of:
Version 1: 'null'
Version 2: 'my_value_for_C'

Should this be an expected behaviour?

I'd like to use this way of fetching revisions because they are actually representations of my object, as opposed to using "O.audits" that give me Audit objects.

Thank you for your help!

recording User options

Has there been any thought to allowing the User record to be stored both as an AR and a string?

I'd like this approach since if a User record is ever destroyed, and you're only recording by AR object, then you've effectively lost the User history aspect of that audit record.

Globally disable auditing

There are cases where we don't want to audit while testing, running migrations, etc... There needs to be a way to turn auditing off and on.

Problem with revision_at bevaior

It seems that created_on/updated_on timestamps are not being added to the attribute list when a revision is being reconstructed. As an example, I created an instance of Comment, then edited it. (It's a polymorphic model, but I have no validation of that at the moment, so please ignore the commentable_id and commentable_type attributes.)

Notice how, in the last command -- c.revision_at(1.minute.ago) -- the created_on and updated_on attributes are nil. I was expecting them to be reverted back to the original.

>> c = Comment.create(:text => "new comment")
Audit Create (0.2ms)  INSERT INTO `audits` (`created_at`, `username`, `action`, `user_type`, `auditable_type`, `user_id`, `version`, `auditable_id`, `changes`) VALUES('2010-04-02 15:26:33', NULL, 'create', NULL, 'Comment', NULL, 1, 3594, '--- \ncommentable_type: \ncreated_on: &id001 2010-04-02 15:26:32.984962 -04:00\ncommentable_id: \ntext: new comment\ncreated_by: \nupdated_on: *id001\nupdated_by: \n')

=> #<Comment id: 3594, text: "new comment", created_on: "2010-04-02 15:26:32", updated_on: "2010-04-02 15:26:32", created_by: nil, updated_by: nil, commentable_type: nil, commentable_id: nil>

>> c.update_attribute :text, "edited comment"
Audit Create (0.2ms)  INSERT INTO `audits` (`created_at`, `username`, `action`, `user_type`, `auditable_type`, `user_id`, `version`, `auditable_id`, `changes`) VALUES('2010-04-02 15:26:59', NULL, 'update', NULL, 'Comment', NULL, 2, 3594, '--- \ntext: \n- new comment\n- edited comment\n')
Comment Update (0.2ms)  UPDATE `comments` SET `updated_on` = '2010-04-02 15:26:59', `text` = 'edited comment' WHERE `id` = 3594
=> true

>> c.reload
<SNIP>

>> c
=> #<Comment id: 3594, text: "edited comment", created_on: "2010-04-02 15:26:32", updated_on: "2010-04-02 15:26:59", created_by: nil, updated_by: nil, commentable_type: nil, commentable_id: nil>

>> c.revision_at(1.minute.ago)
Audit Load (1.1ms)  SELECT * FROM `audits` WHERE (`audits`.auditable_id = 3594 AND `audits`.auditable_type = 'Comment' AND (created_at <= '2010-04-02 15:26:35')) ORDER BY `audits`.version
=> #<Comment id: 3594, text: "new comment", created_on: nil, updated_on: nil, created_by: nil, updated_by: nil, commentable_type: nil, commentable_id: nil>

Weird bug with db:migrate

If in my users model I have:

acts_as_audited :except => [:firstname, :lastname, :email]

I can rollback and db:migrate no problem. BUT if i have

acts_as_audited :only => [:firstname, :lastname, :email]

I get
Could not find table 'users'
(when building from scratch).
It seems like there is a problem with the :only option.... I guess i should mention that i am also using the devise gem.
Thanks!

no entry in audited_changes column

I managed to install acts_as_audited 2.0.0.rc3 on rails3 sample app. Changes to the model are recorded, but the audited_changes column stays empty. Do I have to change something more?

kennethkalmer about 2 hours ago | link
@zettworks, no, can you check against 2.0.0.rc4 (now on rubygems) and open a bug with some re-produceable steps that I can follow (if needed) ?

@kennethkalmer: I tried to use rc4, but get the following error message:
Could not find gem 'acts_as_audited (= 2.0.0.rc4, runtime)' in git://github.com/collectiveidea/acts_as_audited.git (at 2.0.0.rc4).
Source contains 'acts_as_audited' at: 2.0.0.rc3

Switched back to rc3 and get the following warning, when I start the server:
U:\Programming\railsprojects\myproject>rails s
DEPRECATION WARNING: reorder is deprecated. Please use except(:order).order(...) instead. (called from C:in `reorder':)

NoMethodError (undefined method `controller_name' for nil:NilClass): again

Hi,

I've recently updated to v1.1.0, since then my ActiveScaffold setup is broken again.
using git bisect I've found out that commit 12fc5b1 broke it.

the full trace is:
NoMethodError (undefined method controller_name' for nil:NilClass): passenger (2.2.2) lib/phusion_passenger/rack/request_handler.rb:81:inprocess_request'
passenger (2.2.2) lib/phusion_passenger/abstract_request_handler.rb:203:in main_loop' passenger (2.2.2) lib/phusion_passenger/railz/application_spawner.rb:340:instart_request_handler'
passenger (2.2.2) lib/phusion_passenger/railz/application_spawner.rb:298:in handle_spawn_application' passenger (2.2.2) lib/phusion_passenger/utils.rb:181:insafe_fork'
passenger (2.2.2) lib/phusion_passenger/railz/application_spawner.rb:296:in handle_spawn_application' passenger (2.2.2) lib/phusion_passenger/abstract_server.rb:337:insend'
passenger (2.2.2) lib/phusion_passenger/abstract_server.rb:337:in main_loop' passenger (2.2.2) lib/phusion_passenger/abstract_server.rb:187:instart_synchronously'
passenger (2.2.2) lib/phusion_passenger/abstract_server.rb:154:in start' passenger (2.2.2) lib/phusion_passenger/railz/application_spawner.rb:192:instart'
passenger (2.2.2) lib/phusion_passenger/spawn_manager.rb:257:in spawn_rails_application' passenger (2.2.2) lib/phusion_passenger/abstract_server_collection.rb:126:inlookup_or_add'
passenger (2.2.2) lib/phusion_passenger/spawn_manager.rb:251:in spawn_rails_application' passenger (2.2.2) lib/phusion_passenger/abstract_server_collection.rb:80:insynchronize'
passenger (2.2.2) lib/phusion_passenger/abstract_server_collection.rb:79:in synchronize' passenger (2.2.2) lib/phusion_passenger/spawn_manager.rb:250:inspawn_rails_application'
passenger (2.2.2) lib/phusion_passenger/spawn_manager.rb:153:in spawn_application' passenger (2.2.2) lib/phusion_passenger/spawn_manager.rb:282:inhandle_spawn_application'
passenger (2.2.2) lib/phusion_passenger/abstract_server.rb:337:in __send__' passenger (2.2.2) lib/phusion_passenger/abstract_server.rb:337:inmain_loop'
passenger (2.2.2) lib/phusion_passenger/abstract_server.rb:187:in `start_synchronously'

which makes it very hard to debug :(

Rails 3.0.3 You cannot call create unless the parent is saved

Using the current rails3 branch ... I think rails 3.0.3 introduced a bug. It works on rails 3.0.1, but when I update to rails 3.0.3, I get:

activerecord (3.0.3) lib/active_record/associations/association_collection.rb:550:in `ensure_owner_is_not_new'
activerecord (3.0.3) lib/active_record/associations/association_collection.rb:494:in `create_record'
activerecord (3.0.3) lib/active_record/associations/association_collection.rb:269:in `create'
/Users/dgm/.rvm/gems/ruby-1.9.2-p0@cumpp/bundler/gems/acts_as_audited-574ae9e4d49a/lib/acts_as_audited/auditor.rb:204:in `write_audit'
/Users/dgm/.rvm/gems/ruby-1.9.2-p0@cumpp/bundler/gems/acts_as_audited-574ae9e4d49a/lib/acts_as_audited/auditor.rb:199:in `audit_destroy'

BigDecimal and utf8&ruby1.9?

Some strange error - ruby1.9.2, rails 3.0.3, pg (utf8)

"can't define singleton method "encode_with" for BigDecimal"

No chance to save a column with numeric record.

Working haphazardly in production (ie config.cache_classes = true)

I declare in my application.rb:

audit User, PaymentAccount, Client, Product, Price, Contract, AssignedAdsl, ContractPrice, Role

But in production, only User, Client, Price and AssignedAdsl are audited. In development, all models are audited.

It's weird, but it's true. Does anybody know what might cause this?

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.