简体   繁体   English

纸迹版本控制

[英]Paper trail versioning

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. 我正在尝试使用Paper Trail列出版本,该用户将能够看到版本之间的差异并返回到较早的版本。

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 它说:nil:NilClass的未定义方法'reify'

Does anyone knows, what to do about it and what about the diff versioning? 有谁知道,该怎么办以及diff版本如何?

# 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 谢谢您的帮助

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. 看起来问题在于您正在尝试使用版本对象的ID调用@page.versions[params[:version].to_i] ,但是@ page.versions只是一个集合,并且期望与该ID无关的索引版本对象。

Either of these solutions should work: 这些解决方案均应起作用:

Version.find(params[:version])

Or 要么

@page.versions.find(params[:version])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM