Paper trail versioning
Asked Answered
A

1

1

I'm trying to make a version listing with Paper trail, that user will be able to see a difference between versions and get back to the older version.

I've found out how to make a listing and links to this versions, but for some reasons, I'm getting an error, when I try to reify the last two versions. It says: undefined method `reify' for nil:NilClass

Does anyone knows, what to do about it and what about the diff versioning?

# controller
def edit
@page = Page.find(params[:id])
@versions = @page.versions
@page = @page.versions[params[:version].to_i].reify if params[:version]
end

# Model
class Page < ActiveRecord::Base
validates :title, :presence => true
belongs_to :category
has_paper_trail
end

# View
<% @versions.each do |version| %>
<ul>
<li><%= version.id %> <%= link_to "Previous version", {:version => (version) }%></li>
</ul>
<% end %>
<%= link_to "Go to current version"%>

Thank you for your help

Acuff answered 27/11, 2013 at 10:26 Comment(0)
P
1

Looks like the problem is that you are trying to call @page.versions[params[:version].to_i] with the id of your version object, but @page.versions is just a collection and expect an index unrelated to the id of the version object.

Either of these solutions should work:

Version.find(params[:version])

Or

@page.versions.find(params[:version])
Placoid answered 2/12, 2013 at 16:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.