Ruby on Rails:如何跟踪更改(例如 StackOverflow 实现其修订历史记录)?

发布于 2024-09-25 18:18:14 字数 654 浏览 0 评论 0原文

如果我要使用 Ruby on Rails 实现与 StackOverflow 问题修订历史记录相同的系统,我需要做什么才能实现这一目标?我正在创建一个像维基一样的网站,其中用户贡献的内容可以由其他人更新。我需要能够跟踪这些更改的历史记录,但我不熟悉如何实现这一点。

解决方案:

简而言之,其工作方式是创建一个额外的表来跟踪更改。表中的每一行都有记录更改之前存在的数据的“快照”(或仅更改的数据)。

有许多 Ruby Gems 已经完成了大部分工作。以下是处理版本控制/修订历史记录的宝石列表。看起来 Paper Trail 是目前最流行的这样做的宝石。 Ryan Bates 录制了一个 RailsCast,提供使用 Paper Trail 的概述

If I were to implement a system identical to the StackOverflow question revision history using Ruby on Rails, what would I need to do in order to achieve that? I am creating a site that acts like a wiki where user contributed content can be updated by other people. I need to be able to track the history of these changes, but I am not familiar with how to implement this.

Solution:

In a nutshell, the way this works is to create an extra table to keep track of the changes. Each row in the table has a "snapshot" of the data as it existed before the record was changed (or just the data that changed).

There are a number of Ruby Gems that have already done most of the work. Here is a list of gems that deal with versioning/revision history. It looks like Paper Trail is currently the most popular gem for doing this. Ryan Bates has recorded a RailsCast providing an overview of using Paper Trail.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

茶花眉 2024-10-02 18:18:14

编辑条目时,您不会删除(旧)条目,只需添加具有新版本号的新条目。当您想要检索要显示的条目时,您可以选择版本号最高的条目。当您想要检索条目以显示其修订历史记录时,您可以选择所有条目并按版本号对它们进行排序。

When an entry is edited, you don't delete the (old) entry, you just add a new entry with a new version number. When you want to retrieve an entry for display, you pick the one with the highest version number. When you want to retrieve an entry to show its revision history, you pick all of them and sort them by version number.

浮生未歇 2024-10-02 18:18:14

我知道这已经过时了,但任何遇到此问题的人都应该查看 Paper Trail

I know this is old but anyone who runs into this you should checkout Paper Trail

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文