简体   繁体   English

使用paper_trail保存版本注释

[英]Saving version comments with paper_trail

I have a model ( Candidate ) that I need to keep track of changes, version diffs, who changed it and any comments they had regarding the change. 我有一个模型( Candidate ),我需要跟踪变化,版本差异,谁改变它以及他们对变化的任何评论。 I love paper_trail and it is exactly what I need in almost every way, but I'm wondering what the best way to store "change comments" is. 我喜欢paper_trail,这正是我几乎所有方面所需要的,但我想知道存储“改变评论”的最佳方式是什么。 I've been thinking of implementing one of three options: 我一直在考虑实施以下三个选项之一:

  1. Add a comments column to my versions table. comments列添加到我的versions表中。 If I went this way I'm not quite sure of the best way to actually update that information. 如果我这样做,我不太确定实际更新该信息的最佳方式。 Maybe candidate.version.comments = @comments would work? 也许candidate.version.comments = @comments会起作用吗? Is it bad to add custom columns to paper_trail's table? 向paper_trail表中添加自定义列是不是很糟糕?

  2. Use paper_trail's metadata to store the comment. 使用paper_trail的元数据来存储评论。 It doesn't seem like this was the intention for the metadata, but maybe it would work? 这似乎不是元数据的意图,但也许它会起作用?

  3. Add another table as belongs_to :candidate that would keep track of the comments and version . 添加另一个表作为belongs_to :candidate将跟踪commentsversion This seems gross - would I also need to have this new table belong to the versions table? 这看起来很糟糕 - 我还需要让这个新表属于版本表吗?

Any insight would be much appreciated. 任何见解都会非常感激。 I've been pretty focused on finding a solution with paper_trail since I've used it before but I'd also consider other gems or options that you've used in the past. 我一直非常专注于使用paper_trail寻找解决方案,因为我之前已经使用过它,但我也考虑过去使用过的其他宝石或选项。

I ended up going with option 1. I created a migration to add a comments field to the version table and added the following to CandidatesController#update 我最终选择了选项1.我创建了一个迁移,将一个注释字段添加到版本表中,并将以下内容添加到CandidatesController#update

if @candidate.update(candidate_params)
    #Add comments if they are available
    @candidate.reload.versions.last.update(comments: params[:comments]) unless params[:comments].empty?

It seems to be working great but I'd appreciate any other thoughts that you have! 它似乎工作得很好,但我很欣赏你的任何其他想法!

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

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