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
Auditing with user support depends on Rails’ caching mechanisms, therefore auditing isn’t enabled during development mode. To test that auditing is working, start up your app in production mode, or change the following options in config/environments/development.rb:
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
120 comments
July 21, 2006 at 04:50 AM
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.July 21, 2006 at 05:22 AM
July 21, 2006 at 05:50 AM
July 21, 2006 at 06:18 AM
July 26, 2006 at 04:12 AM
August 01, 2006 at 06:13 AM
August 01, 2006 at 06:31 AM
August 04, 2006 at 06:07 PM
August 11, 2006 at 07:27 AM
August 11, 2006 at 07:28 AM
August 12, 2006 at 06:05 AM
August 13, 2006 at 11:07 PM
August 14, 2006 at 06:19 AM
August 15, 2006 at 05:46 AM
August 15, 2006 at 06:07 AM
August 21, 2006 at 06:24 PM
August 28, 2006 at 10:15 AM
August 29, 2006 at 10:08 AM
August 29, 2006 at 10:39 AM
August 30, 2006 at 06:54 PM
August 30, 2006 at 07:07 PM
August 31, 2006 at 05:14 AM
August 31, 2006 at 03:12 PM
September 05, 2006 at 02:57 AM
September 05, 2006 at 04:30 AM
September 05, 2006 at 05:37 AM
September 05, 2006 at 05:52 AM
September 05, 2006 at 07:39 AM
September 05, 2006 at 02:05 PM
September 07, 2006 at 05:11 PM
October 10, 2006 at 01:16 PM
October 10, 2006 at 03:27 PM
October 12, 2006 at 05:53 AM
October 20, 2006 at 03:52 AM
October 20, 2006 at 05:23 AM
November 07, 2006 at 12:29 PM
November 14, 2006 at 01:02 PM
November 14, 2006 at 01:20 PM
November 14, 2006 at 01:34 PM
current_userthat returns the username. Let me know how it works out for you.November 19, 2006 at 12:43 AM
November 29, 2006 at 09:02 AM
script/generatewithout any arguments? Here's what I see for installed generators:November 29, 2006 at 09:42 AM
audited_migration, notaudited_model.November 29, 2006 at 09:44 AM
November 29, 2006 at 12:22 PM
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
December 28, 2006 at 02:50 PM
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!
January 05, 2007 at 10:10 PM
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.
January 09, 2007 at 11:33 PM
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!
January 19, 2007 at 09:52 PM
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!
January 25, 2007 at 10:30 AM
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?
January 25, 2007 at 01:39 PM
Camilia:
Nope. It doesn’t record changes to associations. That’s not a feature that I need, but patches are welcome.
January 25, 2007 at 04:41 PM
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!
February 10, 2007 at 11:05 AM
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.
February 10, 2007 at 05:19 PM
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.
February 14, 2007 at 01:10 PM
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.
February 14, 2007 at 04:31 PM
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.
February 22, 2007 at 04:12 PM
josh,
There already is a model for it:
February 22, 2007 at 04:31 PM
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.
March 13, 2007 at 06:22 AM
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.
March 18, 2007 at 05:27 PM
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.
March 19, 2007 at 01:01 PM
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.
March 31, 2007 at 07:00 PM
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!
March 31, 2007 at 07:25 PM
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?
April 05, 2007 at 04:57 AM
Meng,
April 05, 2007 at 10:16 AM
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
April 06, 2007 at 03:43 PM
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:3April 12, 2007 at 09:18 AM
Steve,
It “works for me™” on a fresh rails 1.2.3 project. Feel free to email or IM me with more details.
April 12, 2007 at 09:35 AM
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.
April 26, 2007 at 04:22 PM
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. :-)
May 01, 2007 at 07:14 PM
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.
May 01, 2007 at 07:23 PM
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
May 04, 2007 at 11:48 AM
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”.
May 04, 2007 at 12:12 PM
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.
May 05, 2007 at 12:23 AM
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:NilClassMay 16, 2007 at 02:22 PM
I’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?
May 29, 2007 at 11:25 PM
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.May 30, 2007 at 09:36 AM
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?
May 30, 2007 at 11:17 AM
John,
Sounds like you’re running in development mode. Check out the caveats section in the post or the plugin’s README.
May 30, 2007 at 11:23 AM
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.
May 30, 2007 at 12:55 PM
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!
June 11, 2007 at 03:15 AM
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.
June 18, 2007 at 03:02 PM
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:)
July 12, 2007 at 03:54 AM
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.July 12, 2007 at 04:12 AM
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…
July 17, 2007 at 06:48 PM
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!
August 05, 2007 at 02:02 AM
Kris,
See the “Auditing in Rails” section above. It shows that you need to declare “audit MyModel” and define current_user in
ApplicationController.August 05, 2007 at 08:05 AM
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
August 07, 2007 at 06:45 AM
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
August 07, 2007 at 08:53 AM
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.
August 09, 2007 at 12:22 PM
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.
August 09, 2007 at 02:21 PM
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?
August 11, 2007 at 07:33 PM
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.
August 17, 2007 at 11:12 AM
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
August 23, 2007 at 03:20 AM
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.
August 23, 2007 at 05:33 PM
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.
August 25, 2007 at 01:10 AM
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.
August 25, 2007 at 09:50 AM
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 ?
August 25, 2007 at 10:21 AM
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.
August 31, 2007 at 03:25 PM
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’]
August 31, 2007 at 03:27 PM
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.August 31, 2007 at 03:52 PM
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
September 04, 2007 at 05:37 AM
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
September 14, 2007 at 10:08 AM
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.
September 14, 2007 at 10:15 AM
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) endSeptember 16, 2007 at 01:26 PM
wow I make it work with acts_as_rateable and hmp =)
October 09, 2007 at 09:18 AM
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!
October 14, 2007 at 11:43 PM
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
November 15, 2007 at 08:40 PM
Nice plugin =)
November 25, 2007 at 10:41 AM
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.
November 26, 2007 at 11:00 PM
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
November 28, 2007 at 10:40 AM
acts_as_audited does work with Rails 2.0.
However, you have to go through a little bit of pain with acts