acts_as_audited
acts_as_audited is an Active Record plugin that logs all modifications to your models in an audits table. It uses a polymorphic association to store an audit record for any of the model objects that you wish to have audited. The audit log stores the model that the change was on, the “action” (create, update, destroy), a serialzied hash of the changes, and optionally the user that performed the action.
Auditing in Rails
NOTE: read the caveats section if the following isn’t working.
If you’re using acts_as_audited within Rails, you can simply declare which models should be audited. acts_as_audited can also automatically record the user that made the change if your controller has a current_user method.
class ApplicationController < ActionController::Base
audit User, List, Item
protected
def current_user
@user ||= User.find(session[:user])
end
end
Caveats
config.cache_classes = true
config.action_controller.perform_caching = true
Customizing
To get auditing outside of Rails, or to customize which fields are audited within Rails, you can explicitly declare acts_as_audited on your models. The :except option allows you to specify one or more attributes that you don’t want to be saved in the audit log.
class User < ActiveRecord::Base
acts_as_audited :except => [:password, :credit_card_number]
end
Installation
You can grab the plugin by running:
script/plugin install git://github.com/collectiveidea/acts_as_audited.git
Run the migration generator and migrate to add the audits table.
script/generate audited_migration add_audits_table
rake db:migrate
Upgrading
Those upgrading from version 0.2 need to add 2 fields the audits table:
add_column :audits, :user_type, :string
add_column :audits, :username, :string
122 comments
Auditmodel, so you can retrieve all the audits for a model by calling: If you have an instance ofAudit, you can also callaudit.auditableto get the model that the audit record is for.current_userthat returns the username. Let me know how it works out for you.script/generatewithout any arguments? Here's what I see for installed generators:audited_migration, notaudited_model.There is something wrong and I can’t lay my finger on it. In a view that lists found entries from the audits table, these work… <%= audit.auditable_type %> <%= audit.username %> <%= audit.action %> <% for change in audit.changes ><= change >
< end %> <%= audit.created_at %> <%= audit.auditable_id %>
but no matter what, this will toss an syntax error…
<%= (audit.auditable_type == ‘Placement’ ? (link_to ‘Show Placement’, { :controller => ‘placements’, :action => ‘show’, :id => audit.auditable_id } )) %>
so I cannot make conditional links to the actual records which is something I would really like to do
Craig
Hi,
A newbie here.. I thought that this plugin is the best suited for my need. I am able to install it, but I cannot move on after executing
I get some error. It says:Can you please help me? Many thanks!
Chris,
Not sure what is causing that error. What version of Rails are you using? This plugin was developed using 1.1.x, but I’m using it in a 1.2 project now, so I know it works.
Thanks Brandon.
I am now into 1.2.1. Tried it again, but i’m still getting the same error.
What do you think could be wrong? Any insight on this?
Many thanks!
I’m reading about the plugin and I knows is what I nees because I need to ansewer the same kind of questions than Brandon. The problem is that is my first time with ruby, and with plugin, and eventhough I understand english, I ``m not really sure how can i use this wonderful act_as_audited… I`m working on that. so if anybody has something that explains it in spanish, or step by step in english, I’ll be thankful, happy, and closer to get this think working. thanks!
Ok I finally got it. I didn`t know where to make the changes; now I understand that in every model you want to audit you have to put: act_as_audited Now here is my new question: I have a table “people” that is related wuith the table “area” through the table “peoplearea”, meaning that each person may have many areas. The “peoplearea” and the “people” models are being audited, and it works. The problem is that if I’m editing a person info, and I add or delete a new area, the “audits” table show this changes as destroying or creating the table “peoplearea” and I need to be saved as a change made over the person. Is this possible with this plugin?
Camilia:
Nope. It doesn’t record changes to associations. That’s not a feature that I need, but patches are welcome.
I’ve finally got the plugin to work!!! It’s really great. It’s what I actually need.
But, I need more help. Does the user object need to have exactly the same field names as the audits table (user_id, user_type, and username) for it to actually work? I tried to turn on caching for the dev environment, and to put the current_user method in the application controller, but it still doesn’t log anything under the 3 user columns.
What must I do? Am I missing anything at all? Thanks!
Chris,
Nope.
Did you declare the models to audit in the controller?
If you did, and it is auditing changes and not the user, then I would check to make sure that your current_user method on your controllers returns an ActiveRecord object or a string.
I’ve been trying to interface this with the existing acts_as_authenticated for current_user support, but I cannot for the life of me update the username or associated user. Someone above has had this previously but did not provide any information.
Skiz,
I use it with acts_as_authenticated, it should “Just Work”(TM). Have you tried it in production mode? It wasn’t working for me in development the one time I tried (even with caching enabled), but I know it works in production.
First off, thanks Brandon for an outstanding plugin. I am curious though, if it is possible to return(/display) all audits in total and chronologically as opposed to on a per user basis? I am a bit new to ror in general but I was thinking maybe I could make an additional model that also refers to the audits table. Would that work? Poor form? Is there another way? Thanks for any insight.
josh,
There already is a model for it:
Thanks for a simple, to the point plugin, works exactly as expected. Saved a lot of time. Is it listed in Rails Wiki, I could not find it there, had to rely on Google. Anyway great work.
Its just that I dont usually audit the creation of a record, as this stands as the record itself until the first change which is audited.
Adam,
That’s a great suggestion. I probably won’t have time to add features to this plugin for a month or so, but I’m open to taking patches.
I like this plugin, but I’ve run into a weird problem and I’m wondering if you have any advice on solving it.
In my application I have an Address model, with a :coords attribute, implemented with GeoRuby’s Point class.
I installed acts_as_audited and told it to audit Address. It works fine in production mode, and in development mode with caching enabled.
However, when I run my unit tests, I get lots of errors about undefined methods on Point. If I take the audit statement out, the errors go away.
Running a unit test in the debugger, I find that at the point when I try to call, say, Point.from_lon_lat (a class method), Point is a subclass of Object with no geometry-related methods, rather than the subclass of Geometry it should be.
Obviously I’m not asking you to study up on GeoRuby or debug my problem for me, but I thought you might have some thoughts on why the presence of an audit statement somehow makes Point refer to a different class.
Well, that didn’t take so long. The answer is that referring to the classes in application.rb changed the order in which they were loaded, revealing a previously hidden bug in my code.
(In case anyone’s curious: I had a local extension to the Point class. When my extension was loaded after GeoRuby, it altered GeoRuby’s Point. But when the extension was loaded first, or without GeoRuby, it created its own Point class. The solution was to require GeoRuby and explicitly identify the Point class to be extended.)
Anyway, uh… yeah! Cool plugin! Sorry for the interruption! Carry on!
Brandon, thanks for the cool plugin! Just installed it and works like a charm.
I am thinking of using the audits table as the source of input for a dashboard interface for my app. I am able to pull out several arrays of the relevant Audit records off the table and flatten them as one big array. E.g. latest list of messages, todo items, comments, etc. all in one array. However, before displaying them, Next I want to sort them according to created_at. I can update the audit.rb class directly and add the “def <=>(o)” method there but am wondering if there is a cleaner way of doing this?
Meng,
I am running rails 1.2.3. What I found weird is that it fails on the second model and not the first. If I comment out the Account model in the audit statement in Application Controller, it works. Any suggestions?
- Nicholas
I cant even install this on Rails 1.2.3. The command line spits out the following errors…
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/depende ncies.rb:266:in `load_missing_constant': uninitialized constant CollectiveIdea:: ActionController (NameError) from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_su pport/dependencies.rb:452:in `const_missing' from script/../config/../vendor/plugins/acts_as_audited/init.rb:8:in `lo ad_plugin' from /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initializer.rb:40 1:in `load_plugin' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_su pport/core_ext/kernel/reporting.rb:11:in `silence_warnings' from /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initializer.rb:40 1:in `load_plugin' from /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initializer.rb:18 5:in `load_plugins' from /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initializer.rb:18 5:in `each' from /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initializer.rb:18 5:in `load_plugins' ... 6 levels... from /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/generate .rb:1 from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' from script/generate:3Steve,
It “works for me™” on a fresh rails 1.2.3 project. Feel free to email or IM me with more details.
hey Brandon, thanks for the plugin… The username column is not being filled in in the audit table. I think its because my user model uses login instead of username as the human readable string that identifies the user. so in the audit.rb I changed the line self.username = user to self.username = user.login. But it still doesn’t work. Also current_user is already defined “we use the acts_as_auth..” plugin. Iam a little new to ruby but I can’t figure out how to get the username column to be filled in correctly.
Great stuff, thanks.
If I don’t specify audit in ApplicationController, then the sweepers aren’t registered and so audits aren’t created with user information.
But if I specify audit on the controller, then the :except option to acts_as_audited is ignored on the observed models.
Would be nice to have my cake and eat it too. :-)
Sheldon,
You should be able to have your cake and eat it too. Specifying audit in the controller simply calls acts_as_audited on the models IF it hasn’t already been called.
Ok lets see if I can ‘splain this. I am using the beast forum software in my app In the post and topic model it specifies that body and title are attr_accessible respectively. (these are the only places in our app we do this) So I excepted all the other fields but I get this error NoMethodError (You have a nil object when you didn’t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each): /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1671:in `attributes=’ /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1505:in `initialize_without_callbacks’ /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:225:in `initialize’ /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations/has_many_association.rb:13:in `new’ /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations/has_many_association.rb:13:in `build’ .//app/controllers/topics_controller.rb:25:in `create’ /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in `transaction’ /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:95:in `transaction’ .//app/controllers/topics_controller.rb:24:in `create’
I tried removing the attr_accessible on those filds but I got other errors. So I guess my question is why doesn’t it work even when I exclude all the fields except the attr_accessible fields.
Thanks in advance, Tom
Brandon, In addition to my previous post I was wondering why when I disabled the cache the acts_as_audited plugin was still “in effect”.
Tom,
There’s actually a Rails bug that prevents you from using
attr_protectedandattr_accessibleon the same model, and acts_as_audited usesattr_protected :audit_idsto prevent malicious users from messing with the audit associations.I’m not sure what you mean by your second question.
Hello,
Has anyone used this plugin with Goldberg (link below)? I am currently getting an error within Goldberg only when I have auditing enabled for a particular model. If I disable auditing by commenting out of the application controller, I no longer get any errors. This error only ocurrs when using Goldberg related functionality but the rest of the application works fine.
Below is a bit more details of the issue. Dave from Goldberg Forums is currently assisting me with this but if anyone has used Goldberg and has a workaround, any guidance will be greatly appreciated. Thanks.
Goldberg http://goldberg.240gl.org/home “Goldberg is a Ruby on Rails generator that enables you to set up fully-featured websites within minutes”
Steps to Reproduce: Administration > Setup > Controllers / Actions Choose Application and then a controller. Then click on ‘Add New Action’ and error occurs immediately. It will also occur if you try clicking on other parts of interface or reaching other pages.
Environment: Rails v1.2.3 Goldberg v0.2.0 MySQL 5.0.26-community-nt WEBrick Plugins: userstamp and acts_as_audited.
Sincerely,
ANR
Error 1:NoMethodError in Goldberg/controller actionsController#new_for You have a nil object when you didn't expect it! The error occurred while evaluating nil.controller_nameError 2:NoMethodError in Goldberg/controller actionsController#show undefined method `controller_name' for nil:NilClassI’m using acts_as_authenticated and userstamp with acts_as_audited. Has there been a resolution on how to get the current_user in your controller without interfering with these plugins?
Doesn’t including AuthenticatedSystem in my ApplicationController bring the current_user method to all controllers?
For userstamp I’m also setting User.current_user (as a cattr_accessor) so if this solution is better, I could use this as well.
I’ve read through many of the comments but haven’t reached a conclusion. I’m running out of ideas. Anyone?
John,
I’m not familiar with userstamp, but acts_as_audited should “Just Work™” with acts_as_authenticated if you’re declaring
audit MyModelin your controller.The comments on this post about
User.current_userare no longer relevant. acts_as_audited was updated and that has been removed.Thanks for the info Brandon (and sorry for the multiple posts. I got a proxy error and my post timed out several times. It must have posted anyway).
I’ve tried using the “audit MyModel” within my App controller and the controller in question. The only method I’ve been able to get the auditable plugin working is by adding acts_as_auditable to the model. In this case it adds a record, but doesn’t put any data in the user fields.
I’m going to do some more debugging to figure out what I’m missing. Do you have any other ideas?
John,
Sounds like you’re running in development mode. Check out the caveats section in the post or the plugin’s README.
Right on! I had the cache vars set to true but rails reset one of them to false at a later spot in the dev environment config.
Everything seems to be working great. Thanks for the plugin! I remember implementing something like this in PHP about a year ago without a framework and it was a hassle.
The topic seems to have been dropped, but way back in the early comments you mention possibly adding versioning (allow individual fields to be reverted). I definitely vote for this!
I just took out acts_as_versioned from my app because it is simply too much hassle. Requires two database tables for every model which I got sick of maintaining. I also think acts_as_versioned gave me a big speed hit but I’m still testing that.
Anyway, the “log the diffs” model is much better for versioning IMHO. Thanks!
carlivar,
Just for you, I’ve updated acts_as_audited to include some sort of revisioning. Check out my latest post for more info. I’d love to get your feedback.
This works:
class PatientDetail < ActiveRecord::Base
end
if I add the following it ceases to work
class ApplicationController < ActionController::Base # Pick a unique cookie name to distinguish our session data from others’ session :session_key => ‘_ClinicCare_session_id’
end
if I comment out “audit PatientDetail” it will work again but does not pass the user through to the log. I have checked to see if there is a value for @user and there is one.
I have run the tests and they pass.
Any help is good help:)
John,
Please read the caveats section in the post and the plethora of other comments about the same issue.
audit Modelin the controller depends on Rails caching, and is therefore is disabled by default in development mode.would be cool to have the possibility to completely disable the saving of a delete-action, since this makes trouble, the referring objects are not existing anymore…
Hi Brandon,
Thanks for this plugin, I just have one quick question though.. I can’t seem to get the user columns filled in.
If I have done this in my dev environment:
and this
where should I put the
protected def current_user @user ||= User.find(session[:user]) endsuch that I may have the three user columns filled up? Sorry if this is a very lame question. I’m not too good with RoR. :)
Thanks so much in advance!
Kris,
See the “Auditing in Rails” section above. It shows that you need to declare “audit MyModel” and define current_user in
ApplicationController.Hi, I have one problem, I’m auditing an “Article” model wich has “Title” and “Text” fields. The problem is, when I create an article, the event is logged correctly, but in the “changes” column I have something like this:
-title:- a title text:
- some text
So when I access the Article in this way: article.audits.first.changes I get {“text”=>[nil, “a title”], “title”=>[nil, “some text”]}
so that article.audits.first.changes[:title] returns NIL
What’s wrong? The problem is the same with every model and field, I always have a NIL object first.
Thanks, and I hope that this will be useful for others with the same problem
Bugbuster,
For each modification, acts_as_audited stores an array with the old attribute and the new attribute. On create, the old attribute obviously didn’t exist, so it will always be nil. So to get to the new attribute, you could do article.audits.first.changes[:title].last
Brandon
There was a comment made about the ability to ignore delete / destroy actions altogether. I agree, but I found an option that I liked better for my situation, acts_as_paranoid. This plugin overrides destroy by setting the deleted_at timestamp column to the current time. It also overrides find and count to ignore “deleted” items. This still effectively deletes them, but allows this plugin to resurrect them. Hope this helps someone, and Brandon, thanks for the great plugin.
I also noticed that this will create an audit trail even if no attributes are changed. This may be necessary for some instances, but I don’t care if nothing is actually modified. Changing line 167 in lib/acts_as_audited.rb to:
self.audits.create(:changes => @changed_attributes, :action => action.to_s, :user => user) if !@changed_attributes.empty?
will stop this.
Regarding acts_as_paranoid, it seems that Rick does no longer endorse it.
Still being a Ruby newbie, I managed to write a revive method that will revive destroyed records. In order to get this to work, I added a before_destroy callback that will add every attribute’s value to the @changed_attributes hash so that the full state of the model is audited. I’ve posted a diff here. If there’s a better way to do this, I’m all ears.
Using acts_as_audited, is there a way to have the user attributes in the audits table be populated also when using script/console or are the sweepers depending on being used through a running app?
Peter,
There is a #revision method on Audit that will reconstruct the model for that revision using the audits.
At this time, there isn’t a way to populate the user field from the console. It would probably be a nice addition though.
Hi Brandon, I seems to gr8 plug in over acts_as_versioned in space saving. I have one problem that, If some change are made in the table and I dont know on what column changes are made, then how would I fetch this changes. Or rather display the changes in well manner. Because if I chack for any column with name then it give nil method error if for that column no changes are made. Please reply if anyone has the solution.
Thanks
If I am understanding this correctly, reverting to a specific version number actually reverts to the number preceding that number? (i.e. to revert to the first version I need to select revision 2, to revert to version 3 I select and save version 4)
Or am I doing something incorrectly?
task.revision(4) task.save This will give me version 3.
BTW – This plugin is amazing.
Hi Brandon
I am using acts_as_audited for audit trail in production environment.
In order to view the audits table within my apps, I had set up a controller with a ActiveScaffold config block.
AS displays fine in List but when I click next or any of the pages in the pagination, I get the following message
TypeError in Audits#update_table Showing vendor/plugins/active_scaffold/frontends/default/views/ _list_record.rhtml where line #7 raised:
BigDecimal can’t be coerced into BigDecimal
How can I workaround this BgDecimals issue. BTW, I have absolutely no issue in using Active Scaffold to display the other 200 _ tables in my apps . Only in the audits atble am I having the BifDecimnal issue.
Ch Chee,
If you would leave a real email address, you would have gotten my email the last time you posted explaining that I’m pretty sure the issue you’re running into is not an acts_as_audited issue. I’ve never used ActiveScaffold, so I can’t help you out.
Hi Brandon
TQ for responding !
I have found the solution to the Big Decimal issue as it is actually an unfixed rails issue and Michael Raiden has a temporary solution which actually works !
BTW, the email adress is my working email address and recently the spam filter had been tightened up. Were you getting the BW filter rejection ?
nice to see this plug-in, I had created something very similar to this for my rails environment, with the exception of making it standalone gem usable at the model level, and not polymorphicly associating it with the audited class.
you should add these to your exception filter ‘changed_on’, ‘updated_at’, ‘created_at’, ‘created_on’, ‘updated_on’, ‘type’, ‘position’, ‘lock_version’, ‘parent_id’, ‘lft’, ‘rgt’, ‘quote’, ‘template’]
Sal Scotto,
id,type,lock_version,updated_atandcreated_atare already ignored. I could see situations where people would actually want to audit the other fields, so I don’t think that ignoring them in the plugin is a good idea. You can add those for your specific model.Hello, first of all nice plugin. i have a problem like a few people here. i can’t get the plugin to log user data. caching settings are done- the plugin isn’t logging any user data on a linux production box, though.
For authentication i’m using the latest active_rbac version. active_rbac provides a current_user function that is mixed in from active_rbac. current_user gives me a User record. does the plugin need the @user variable, or is a valid AR object from current_user enough? any hints to get it work ith the latest active_rbac version?
the latest active_rbac demo version can be found at: svn://rubyforge.org/var/svn/active-rbac/active-rbac/trunk/demo
would be great if could have look why it isn’t working as axpected.
tia
Daniel
Hi,
I’m trying to use this plugin with restful_authentication (should be the same as acts_as_authenticated).
At first I was setting my config incorrectly (in my main environment.rb file instead of development.rb), but after fixing this mistake I get correctly logged user_id and user_type. However, I don’t get username logged.
I don’t have username field in my User model – I’ve got custom full_name method that uses 2 fields – first_name and last_name.
Is there any easy step by step guide how to make username work with custom field/method in User model?
Thank you in advance
Szymon,
The username field is just for those that don’t have a user model and just want to store the user as a string (e.g. using HTTP basic auth). If you have a user model, it will set the user_id and user_type, which should be all you need.
I modified the plugin a bit to do some things I need it to do in my application.
Find all audits of an audited class acts_as_audited.rbdef audits(*args) options = {:conditions => {:auditable_type => class_name}, :order => 'audits.version desc'}.merge!(extract_options_from_args!(args)) Audit.find(:all, options) endSupply either one or an array of audited classes, along with optional arguments, and have audit records returned audit.rbdef self.pool(classes, *args) classes = classes.is_a?(Array) ? classes : [classes] options = extract_options_from_args!(args).merge!({:conditions => ["audits.auditable_type in (?)", classes.map{|x| x.class_name}]}) find(:all, options) endwow I make it work with acts_as_rateable and hmp =)
So, since Restful Authentication defines login, password, and password as attr_accessible. Does that mean I can’t define my User model as auditable?
thanx!
Howdy Brandon?
First off, great plugin, it is what I have been looking for and it fits my needs for the most part. However, I wonder if I could audit on association columns as well. I mean, I have a Requirement model class that “habtm” Projects model class. So, anytime, a user makes a change only to associate/disassociate which projects are affected/not affected, system essentially made a change in the associated column (Projects model) which means that “audit” did not pick any change. This is a dilemma, even though, I understand that the change occurred in the Projects model yet from the user standpoint, the change occurred on the Requirements.
Please help! Any ideas to go about resolving this problem will greatly help.
Thank you very much for considering. —Sachin
Nice plugin =)
Sachin,
As I mentioned in a comment above, auditing associations is not a feature I needed, but I’d gladly accept a patch that implements it.
To solve your problem, you could change the habtm to a has_many :through and audit the join a model.
Does acts_as_audited work with Rails 2.0? I tried running the migration and get a missing acts_as_list method error, I assume because that is now a plugin in Rails 2….
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.99.0.8178/lib/active_record/base.rb:1334:in `method_missing’: undefined method `acts_as_list’ for #<class:0x134aed0> (NoMethodError) from /Users/epugh/Documents/code/hightechcville/trunk/vendor/plugins/acts_as_audited/lib/audit.rb:14
acts_as_audited does work with Rails 2.0.
However, you have to go through a little bit of pain with acts_as_list – you might have to rename the plugin folder in vendor/plugins to ‘01_acts_as_list’ or similar in order for it to load before acts_as_audited requires it.
@Rails 2.0
Instead of messing with directory names, simply set in config/environment.rbI’m using acts_as_audited with ActiveScaffold. When auditing is enabled and I try to open a nested scaffold, I get an exception. Apparently, this happens because acts_as_audited is not designed to handle callbacks for nested actions (due to components).
For example, the Clients scaffold shows a list of clients. If I click on the meeting registrations for a client, a nested scaffold showing the registrations should open. The sweeper tries to execute before_clients_nested, then before_meeting_registrations_table, then after_meeting_registrations_table, and then—an error, because the sweeper’s controller was set to nil the first time it executed an after callback, and then it tries to execute what should be the after callback for the clients controller. How difficult is it to modify acts_as_audited to work with components?
I wrote a blog post about how to get acts_as_audited to work in Rails 2 for anyone who has been having trouble with it.
Thanks Patrick.
I’m going to be using acts_as_audited in another project soon, so there should be a slew of updates, including removing the dependence on acts_as_list.
It turns out that acts_as_audited can be used with ActiveScaffold simply by modifying a line in audit_sweeper.rb:
http://groups.google.com/group/activescaffold/browse_thread/thread/a717fa3c8b7433a6
Also, I modified the write_audit method in acts_as_audited.rb so that dates/times would be serialized in a YAML-compatible format. (I had changed the default date and time formats for my application, and the plugin was using those formats to serialize changes.)
i can’t get this plugin to work with rails 1.2.6: undefined method `extract_options!’
Research revealed that this function was added with rails 2.0.1 recently. Probably the plugin was updated too but that update broke backwards compatibility?
micky: thanks, I recently made some updates and didn’t test them against rails 1.2. It should be fixed now.
Newbie questions for this great plugin:
In the app/models/*.rb files I want audited, I’ve included an “acts_as_audited” line. Do I need to specify the audited classes in the app/controllers/application_controller.rb as well?
On a possibly-related note, I’m having problems getting the Model.revision_at(date) working. Revisions 0 and 1 seem to be duds. Is this proper behavior?
Hi Brandon,
Very nice plugin, just what I was looking for. Besides the BigDecimal problem, is there any chance to get hbtm relations audited? I’ve got a few structures that have m:n dependencies and would like to record changes to that relationship.
Thanks, Pefmeister
Thanks for the contribution to the community.
fwiw, I’m unable to get user logging to work with restful_authentication with any amount of current_user wrangling. I can see that write_audit is only called with one parameter so the user value always is set to nul. Have I configured it wrong? Is the execution not supposed to go from eg audit_create->write_audit this way?
I am noticing a lot of rows in the audits table where the value in changes is ==={}. Why is it logging updates that have no changed data. I’m guessing it is because I take the params for the form and do an update_attributes on the object (even if the user did not actually change and form data)
Ron B,
I’ve been noticing this too. It appears that the “dirty tracking” code in Rails sees an attribute as changed, even if you set it to the same value.
I don’t think it used to be like that, but I’m not sure at what point it changed. I’ll try to come up with a workaround and post here when I have something.
Speak your mind: