Paper_Trail: Show Diff Between Versions

I’m new to Rails…using RubyMine as an IDE.

I have Paper_Trail saving previous versions of the data “xoi_qb”. My
view is currently showing the current and previous data as I’d like, but
I would like to show the diff between the current version “xoi_qb” and
the previous version “xoi_qb”. For instance, the current version may be
“97” and the previous version may be “94”, and I would like to display
“+3”. I would like to display this difference and add the “+” or “-”
based on the positive or negative change.

In my model, Paper Trail is set to create versions like this:

def get_xoi_qb
xoi_qb = [ ]
self.versions.each do |version|
unless version.reify.nil?
xoi_qb << version.reify.xoi_qb
end
end
return xoi_qb
end
And in my HTML set to display the versions like this:

Previous XOI <% @quarterback.versions.each do |version| %> <% end %>

Not sure how to show the difference between the two versions.

Really appreciate the help.

<%= version.reify.xoi_qb %> dated <%= version.created_at %>

On May 30, 2015, at 11:57 PM, Charles D. [email protected]
wrote:

In my model, Paper Trail is set to create versions like this:
And in my HTML set to display the versions like this:
Not sure how to show the difference between the two versions.
Paper Trail saves a diff, but not at the level you’re thinking of.
Instead of calculating the new value from the old plus the diff, it
saves the attributes that are different from one object to the next. For
example, if you had Widget.create( size: ‘large’, color: ‘blue’) and you
changed it to color: ‘green’ later, the object that Paper Trail saved to
record this change would consist of only the color: ‘blue’ part, the
updated_at from the initial creation of the widget, and a foreign key
back to the original @widget. The updated @widget record would now
consist of size: ‘large’, color: ‘green’, and a new updated_at. When you
navigate back to the original version, Paper Trail first loads the
current value, then overloads any attribute key/value pairs stored in
its version record to restore back to the desired snapshot of the
object.

You’ll have to calculate the difference (through addition or
subtraction) yourself. If you think about it, this is only natural,
since for Paper Trail to save a true diff at the level you’re thinking
of, it would have to understand every possible attribute type and value
scheme. Much of what people use this for is non-numeric data.

Walter