문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top