airblade / paper_trail
- Source
- Commits
- Network (5)
- Issues (4)
- Downloads (9)
- Wiki (2)
- Graphs
-
Branch:
master
-
Will be nice if paperclip support model relations
Comments
-
option to record only changed field (usefull for audit)
6 comments Created 4 months ago by jalbertoto use paper_trail as audit tool is too verbose, maybe an :audit => true will be nice :)
Comments
Sorry, I don't quite follow you. Would you like to be able to specify which attributes PaperTrail pays attention to?
sorry for my english :)
do you know acts_as_audited? is a version plugin too but more designed for audit. Have some nice features i will liek to see in paper_trail:
- you can specify what to watch (acts_as_audited :except => [:created_at]
- only save what changed, so the audit table is more easy to read. For exmaple if i change the name of a user it saves somethign like: "name: -john -newjohn" not the full object.
This is not usefull for versioning, but yes for auditing
No worries about your English!
I do know acts_as_audited. In fact if you look at PaperTrail's README, you'll see it was one of my inspirations. But I wrote PaperTrail because acts_as_audited didn't really do what I needed.
I can see the usefulness of specifying what to (not) watch, so I'll incorporate that. However I think the cost of changing the way the versions are stored outweighs the benefits, so I won't change it as per your second bullet point.
You are right about 2nd point, so can you explain me or show me some example how to create an audit table (not version table) with PaperTrail? becuase in my opinion is not the same.
In version table you need to keep track of the full object so you can back, but in audit table what you need is to know who changed what.PaperTrail first and foremost needs to keep a version table so you can get the full object back. It also stores who was responsible for each change.
If you need a lighter-weight version table, please do fork the code and implement it. I'll be happy to consider pull requests.
-
Is there a way to see all of the changes made by a particular user to all of the models being watched?
Comments
-
My model has one field that change every month. It's a depreciation value cache. But I want to ignore any change in this field (don't create a version). Is it possible? If not, I'm considering to create an class method setting paper_trail_off, changing and then paper_trail_on. Maybe that's the right way to do it. Any ideas?
Maybe implement a feature that allows us to pass those setting to has_paper_trail?
ps: thanks for the awesome gem
Comments
Yes, you can do this:
class Article < ActiveRecord::Base has_paper_trail :ignore => [:title, :rating] endI only added this recently, but you can read about it in the README. I hope it does what you want -- if not, just let me know.
thanks! Is was just building a save_without_version! instance method...
One thing: were can I get an updated gem? gems.github.com it still in 1.1.1
Oh sorry, I should update the readme: new gems are on Gemcutter.
-
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 2 months 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 -
I received the following error when attempting to revert an update:
ArgumentError: syntax error on line 0, col 37: `--- \nreferred_by: Blah\noccupation: !str \n str: electrician\n "@rails_html_safe": false\nname: !str \n str: Abbey Streich\n "@rails_html_safe": false\nfax_number: !str \n str: 978.631.7298 x05457\n "@rails_html_safe": false\ncity: !str \n str: Ipoh\n "@rails_html_safe": false\naddress: !str \n str: 3855 Brekke Bypass\n "@rails_html_safe": false\nzip: !str \n str: "61851"\n "@rails_html_safe": false\nphoto_file_size: 74095\ncreated_at: 2009-12-28 23:02:18 Z\nupdated_at: 2010-01-05 14:58:11 Z\nphoto_file_name: OldWoman.jpg\noutpatient: true\nnotes: !str \n str: ""\n "@rails_html_safe": false\nphoto_content_type: image/jpeg\nid: 54\nuser_id: \nphoto_updated_at: 2009-12-28 15:04:52 Z\nphone_number: !str \n str: 732.727.0168 x9825\n "@rails_html_safe": false\nmale: false\nbirthday: 1889-01-05\nstatus: \nstate: !str \n str: Kuala Lumpur\n "@rails_html_safe": false\nrace: !str \n str: Indian\n "@rails_html_safe": false\n'
from /usr/local/lib/ruby/1.8/yaml.rb:133:in `load' from /usr/local/lib/ruby/1.8/yaml.rb:133:in `load' from /usr/local/lib/ruby/gems/1.8/gems/paper_trail-1.3.1/lib/paper_trail/version.rb:9:in `reify' from (irb):4 from :0Comments
This seems to be a problem with the YAML library bundled with Ruby 1.8. You can reproduce this in irb:
>> YAML.load %q{--- \nreferred_by: Blah\noccupation: !str \n str: electrician\n "@_rails_html_safe": false\nname: !str \n str: Abbey Streich\n "@_rails_html_safe": false\nfax_number: !str \n str: 978.631.7298 x05457\n "@_rails_html_safe": false\ncity: !str \n str: Ipoh\n "@_rails_html_safe": false\naddress: !str \n str: 3855 Brekke Bypass\n "@_rails_html_safe": false\nzip: !str \n str: "61851"\n "@_rails_html_safe": false\nphoto_file_size: 74095\ncreated_at: 2009-12-28 23:02:18 Z\nupdated_at: 2010-01-05 14:58:11Z\nphoto_file_name: OldWoman.jpg\noutpatient: true\nnotes: !str \n str: ""\n "@_rails_html_safe": false\nphoto_content_type: image/jpeg\nid: 54\nuser_id: \nphoto_updated_at: 2009-12-28 15:04:52 Z\nphone_number: !str \n str: 732.727.0168 x9825\n "@_rails_html_safe": false\nmale: false\nbirthday: 1889-01-05\nstatus: \nstate: !str \n str: Kuala Lumpur\n "@_rails_html_safe": false\nrace: !str \n str: Indian\n "@_rails_html_safe": false\n} ArgumentError: syntax error on line 0, col 36: `--- \nreferred_by: Blah\noccupation: !str \n str: electrician\n "@_rails_html_safe": false\nname: !str \n str: Abbey Streich\n "@_rails_html_safe": false\nfax_number: !str \n str: 978.631.7298 x05457\n "@_rails_html_safe": false\ncity: !str \n str: Ipoh\n "@_rails_html_safe": false\naddress: !str \n str: 3855 Brekke Bypass\n "@_rails_html_safe": false\nzip: !str \n str: "61851"\n "@_rails_html_safe": false\nphoto_file_size: 74095\ncreated_at: 2009-12-28 23:02:18 Z\nupdated_at: 2010-01-05 14:58:11Z\nphoto_file_name: OldWoman.jpg\noutpatient: true\nnotes: !str \n str: ""\n "@_rails_html_safe": false\nphoto_content_type: image/jpeg\nid: 54\nuser_id: \nphoto_updated_at: 2009-12-28 15:04:52 Z\nphone_number: !str \n str: 732.727.0168 x9825\n "@_rails_html_safe": false\nmale: false\nbirthday: 1889-01-05\nstatus: \nstate: !str \n str: Kuala Lumpur\n "@_rails_html_safe": false\nrace: !str \n str: Indian\n "@_rails_html_safe": false\n' from /usr/local/lib/ruby/1.8/yaml.rb:133:in `load' from /usr/local/lib/ruby/1.8/yaml.rb:133:in `load' from (irb):24So it looks like YAML cannot parse its own output in your case. I don't know enough about YAML to fix this, but I'll keep looking around to see if I can find a solution.





I agree. It's non-trivial though. If you have any suggestions, I'd like to hear them.
has_versioning(http://github.com/kkurach/has_versioning/tree/master) support it, maybe it can inspire you :)
Thanks for the reference. I'll have a look.
+1 for model relations and I would be happy to collaborate on this feature.
That's an interesting blog post you wrote, Kevin, on auditing and versioning. Nice to see PaperTrail making the cut ;)
I'll have a think about model relations and give you a shout if need be.
If anyone wants to send in patches, that would be great. I can't figure out how to do this in the limited time I have available.
I may come up with something eventually but I'm in the same boat. :) it may be best to handle this on the application domain since the business rules dictate which associations are important and the conditions under which they should be versioned.
That's certainly how I'm doing it at the moment in my apps. It's not ideal but it gets by for now...