纸迹版本控制 [英] Paper trail versioning

查看:86
本文介绍了纸迹版本控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Paper Trail列出版本,该用户将能够看到版本之间的差异并返回到较早的版本.

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.

我已经找到了如何列出此版本的清单和链接,但是由于某些原因,当我尝试对后两个版本进行验证时出现错误. 它说:nil:NilClass的未定义方法'reify'

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"%>

谢谢您的帮助

推荐答案

问题似乎是您正在尝试使用版本对象的ID调用@page.versions[params[:version].to_i],但是@ page.versions只是一个集合并且期望与版本对象ID无关的索引.

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])

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

这篇关于纸迹版本控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆