Every repository with this icon (
Every repository with this icon (
| Description: | acts_as_audited is an ActiveRecord extension that logs all changes to your models in an audits table. edit |
-
Auditing of virtual attributes (e.g. tag_list)
8 comments Created 7 months ago by ledermannI 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.
Comments
-
It's not possible to get at version 0 (i.e. before any changes) of an object.
1 comment Created 6 months ago by airbladeSay 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.
Comments
I've had that issue before and it would be nice to figure out a way around it. Here are a few ideas:
- a rake task that creates the initial audit for all the models
- a conditional when auditing updates to audit the original version if the audit doesn't exist. They may not scale very well because it'll be an extra select when saving every object
- a rake task that creates the initial audit for all the models
-
Changes in audit selects not serialized on rails server start.
3 comments Created 5 months ago by btellesHey 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.
Comments
I've come across this issue too. ActiveReocrd::Base has a #changes method which gives you the changed (dirty) attributes, and you get the result of this method if ActiveRecord has not defined the attribute methods for the Audit model.
2 solutions are to:
1. rename the changes field on the Audit model to avoid the naming conflict
2. explicitly declare the #changes method in Audit to return the changes attributeHeh...I think we already talked about this on Lighthouse. Thanks though!
collectiveidea
Thu Sep 10 05:16:00 -0700 2009
| link
Haha, sorry. Just getting caught up on GitHub issues.
-
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.
Comments
-
a great feature will be to support model relations.
has_versioning(http://github.com/kkurach/has_versioning/tree/master) support it, so can be a start pointComments
-
Wil be great the possibility set what method to user for current_user
Comments
danielmorrison
Thu Oct 29 04:09:16 -0700 2009
| link
An easy way around is to just define a current_user method that calls your method.
def current_user your_current_user_method end -
class User < ActiveRecord::Base include Clearance::User acts_as_audited # it records everything OK # except the user_id which is always null endComments
You need to declare "audit User" in your controller to get the user. Reopen if you are still having issues after adding that.
I added "audit User" to the application_controller, also tried adding it in both places. Nothing works. I've been through all permutations of the tutorial. It records auditable_id, auditable_type, action, changes, and version, but not the user_id.
ok. Can you try pulling the latest changes that I committed yesterday, and let me know if that fixes your issue?
Here is a pastie of my usage: http://pastie.org/635113
I just installed the plugin, and it still isn't getting the user_id
-
It would be useful to store comments with an audit. Such as a note explaining why the change was made.
Comments
I've solved this issue in my fork of this project. http://github.com/EmFi/acts_as_audited.git
-
example has_many :changes conflicts with ActiveRecord::Dirty
0 comments Created 10 days ago by conickalIt'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.
Comments












I don't know if this is possible. acts_as_audited depends on Active Record's dirty tracking, which detects changes to attributes. I wouldn't be opposed to adding this, if you could come up with a clean implementation.
Another idea I had was to allow auditing of any arbitrary data with a record. For example, if I wanted to store the IP of the user. I haven't come up with a good API for it yet, but here are a couple ideas:
Hm, after some investigation I think it would be better to tell other plugins (like acts_as_taggable etc.) to "make the model dirty", so e.g. after setting tag_list to a new value, the "changed_attributes" hash should reflect this change.
did anyone ever come up with a working solution to this? It's a problem I'm looking at right now
I'm looking into the "dirty" method, but I'm wondering if it might affect partial_updates?
I don't know of anyone that is working on this yet.
what do you think of this? Rather than try to come up a generic API, you just add whatever you need to changed_methods hash. I changed self[attr] to send(attr), it didn't break any tests and I can't see that it would cause any problems.
--- a/lib/acts_as_audited.rb +++ b/lib/acts_as_audited.rb @@ -97,6 +97,11 @@ module CollectiveIdea #:nodoc:
@@ -164,8 +169,8 @@ module CollectiveIdea #:nodoc: private
then I used this method in my class to audit the tag list
audit tag changes
def set_tag_list_on_with_audit(context,new_list, tagger=nil)
end
alias_method_chain :set_tag_list_on, :audit
sorry about the formatting
http://github.com/johnsbrn/acts_as_audited/commit/4fe071a58ff16fe558643d2ebcfb2e7daf97f3cd