Every repository with this icon (
Every repository with this icon (
| Description: | Track changes to your models' data. Good for auditing or versioning. edit |
-
Document the public API.
Comments
-
usafull for auditing
Comments
Currently the whodunnit field is populated by calling the current_user method on your application controller (or you can set it manually at the model/migration level).
So you could modify your current_user method to return the user's IP as well as anything else you need, though that may not be ideal for you.
Perhaps the method that PaperTrail calls on the controller to find out whodunnit should be configurable? It would default to current_user but you could then specify, say, current_user_and_ip instead. Does that sound good?
it would be great if its configurable, not only to get he ip, i use authlogic and the current_user method must be private.
Ok, I'll make it configurable.
By the way, PaperTrail works with authlogic's private current_user method.
Another idea would be to add some hooks at certain points to the version table objects lifecycle. This would allow for easy user extension of the version table. What do you think Andy?
Do you mean, for example, a before update hook on the version object? It sounds like an interesting idea, Simon. Did you have anything specific in mind? I don't feel I've quite grasped what you're suggesting!
Hi Andy, Sorry for the quick explanation! I think you've got it though, a set of before/after hooks on the version object would allow for 2 possible future scenarios:
1) Addition of user required fields to the Version table (eg. A string representation of what has changed, IP address, phase of moon etc)
2) Possibly open the door for dealing with associations.
Thanks for the details, Simon. So would this sort of thing do?
It absolutely would! :). I guess we could also patch to pass in a proc to the has_paper_trail method to hide the opening up the Version class bit from the user? Thanks!
-
ActiveRecord::RecordNotSaved thrown, when calling clear on a new record
2 comments Created 28 days ago by 23inhouseIn a case where an association is build (not saved) and then cleared, rails calls destroy or delete.
An exception is thrown - "ActiveRecord::RecordNotSaved: You cannot call create unless the parent is saved".I found adding this fixed it:
def record_destroy
return if new_record? ... end
Maybe it could be added too record_update as well.Here is a case.
class Blog < ActiveRecord::Base
has_paper_trail has_many :posts end
class Post < ActiveRecord::Base
has_paper_trail belongs_to :blog endclass BlogsController < ApplicationController
def action@blog.posts.build @blog.posts.clear #now i dont want it any moreend end
Thanks for the great plugin, i learnt a lot by looking at the code.
Thanks
BenComments
Hi Ben,
I can't seem to reproduce your problem. When I call
@blog.posts.buildand then@blog.posts.clearit works fine (Rails 2.3.4). Where is yourRecordNotSavedexception being raised?Thanks,
Andy











