Paper trail versioning

送分小仙女□ 提交于 2019-12-14 02:46:59

问题


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


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


来源:https://stackoverflow.com/questions/20239835/paper-trail-versioning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!