-
Notifications
You must be signed in to change notification settings - Fork 902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to extend the Version class #231
Comments
@TvL2386 - Please read the README section on Storing Metadata for an example of how to add an initializer for PaperTrail with which you can add / modify the Version class. The class should get placed in |
The problem of development not picking up on changes remains if I put my version class definition in |
That's true. But it is the way to do it for the time being. Maybe we can look at trying to put a reloader in for version 3, I'm not sure what that would entail. |
I'm also looking for an alternative to this, defining methods in initialisers isn't my idea of fun. I actually found this on a project I was working on and decided to move it. If I find a way around it I'll let you guys know :) |
Highly appreciated abepetrillo! |
Unfortunately I've ran out of time a little bit, it doesn't solve the having to restart the server issue, but it fixes the location, I put this in my initializer:
So the model is in the right place, and it has a corresponding spec/models/version_spec.rb. It might be worth looking into requiring the class definition in config/application.rb, but I doubt it'll help! |
FYI, in 2020 as of Version 10 (likely around Version 4+), here's how you extend
# Extend PaperTrail::Version with some of our own methods we use.
#
module PaperTrail
class Version < ActiveRecord::Base # Cannot use ApplicationRecord here so you may need to disable Rubocop for this line with `rubocop:disable Rails/ApplicationRecord`.
include PaperTrail::VersionConcern
def no_change?
self.changeset.empty?
end
end
end |
There is a snippet of code in the docs that misleads to make https://github.com/paper-trail-gem/paper_trail#configuration # app/models/paper_trail/version.rb
module PaperTrail
class Version < ActiveRecord::Base
include PaperTrail::VersionConcern
self.abstract_class = true
end
end I already forked the gem, is it okay if I send a pull request to change that README.md part of the file? # config/initializers/paper_trail.rb
module PaperTrail
class Version < ActiveRecord::Base
include PaperTrail::VersionConcern
self.abstract_class = true
end
end |
Hi guys,
I want to add a way to create a flexible audit trail for my application.
What I want is to select Version objects based on
created_at
anditem_type
.Best way to do this imho, is to add a scope to the
Version
class.I've added the file
app/models/version.rb
and started to extend theVersion
class.When I have this, I'd like to add more logic in the Version class to built an audit trail.
In development the changes are not picked up on. I wonder why this does not work.
I'm also wondering if I'm trying to do something evil here.
Please help me out!
Kind regards,
Tom
The text was updated successfully, but these errors were encountered: