Acts_as_versioned and activerecord-diff problem

Hi,

I’m trying to use acts_as_versioned together with activerecord-diff
plugin. I have a Testcase model which is versioned.

class Testcase < ActiveRecord::Base

acts_as_versioned

include ActiveRecord::Diff
diff :exclude => [:updated_at, :version, :id]

end

In my view, I’d like to show a summary of changes.

So I tried following code in the show.html.erb:

<%
last_version = nil
@testcase.versions.each do |version|
%>

  • <%=version.created_at.to_s(:short)%>: <% if last_version.nil?%> Initially Created <% else %> <% changes = [] differences = version.diff(last_version) differences.each do |field, d| new_value, old_value = *d changes << "#{field.to_s.humanize} changed " < <%=h changes.to_sentence%><% end last_version = version%>
  • <%end%>

    But when I try to enter the page, I got following error:

    NoMethodError in Testcases#show

    Showing /home/lukas/Aptana Studio 3 Workspace/testup/app/views/
    testcases/show.html.erb where line #13 raised:

    undefined method `diff’ for #Testcase::Version:0x7f49b65c5c90

    Extracted source (around line #13):

    10: <% else %>
    11: <%
    12: changes = []
    13: differences = version.diff(last_version)
    14: differences.each do |field, d|
    15: #next if ignored_fields.include?(field)
    16: new_value, old_value = *d

    Seems that the activerecord-diff is not allowed for the versions of
    Testcase, only for testcase itself. But since the versions are managed
    automatically by acts_as_versioned, I do not know how to tell
    activerecord-diff to work with it.

    Can you help me?

    (The only solution I found so far is to manually create temporal
    Testcase from version object and use diff on that one, but there must
    be a better way)

    Thanks in advance

    Lukas Lipavsky