Gamal Tawaf
Gamal Tawaf

Reputation: 125

How do I retrieve a versions at a certain versions with Paper Trails?

I'm working on switching from vestal_version to paper_trail.
I know vestal versions use versions number while paper_trails use timestamps.

paper_trails has a method called version_at(timestamp), but I found a lot of versions in my table with the same exact date so that method will not work as expected.

I need to achieve the following.

widget1 = widget.paper_trail.version(4)
widget2 = widget.paper_trail.version(10)
# there are a couple of way to get the diff 
# using active record diff ( I prefer this to Jeremy Weiskotten's PaperTrail)
changes = widget1.diff(widget2)
# I know I can do 
versions = widget.versions[4]  
# that only returns versions model instead of widget 

Thanks for the help

Upvotes: 0

Views: 472

Answers (1)

usha
usha

Reputation: 29349

you will have to do reify to get the widget object

widget.versions[4].reify

Find documentation and examples here

Upvotes: 1

Related Questions