Reputation: 131
I have a User model, which has one image.
class User < ApplicationRecord
has_paper_trail
has_one_attached :image
end
I decided to paper_trail gem because I need versioning for User attributes. However, I noticed that I don't know how to get versioning information for image.
PaperTrail::Version.where(item_type: "User").first.object
=> "---\nemail:XXXX\n'\ncreated_at: 2021-10-28 13:06:15.206202000\nupdated_at: 2021-10-28 13:06:19.789124000\n"
Does anyone else know how to get previous version of ActiveStorage? I'm using paper_trail gem, so it's the best if paper_trail can do it.
Upvotes: 4
Views: 1107
Reputation: 2052
Ok, I'm a little late to the party, but I have found a need for version tracking on my ActiveStorage models. Here's what worked for me:
/config/initializers
called active_storage.rb
/config/initializers/active_storage.rb
file, add the following code:Rails.application.config.to_prepare do
ActiveStorage::Record.has_paper_trail
end
You should now see version tracking for all subclasses of ActiveStorage::Record
.
Upvotes: 3