Object versioning in Rails, like Papertrail but individual tables

前端 未结 2 940
不思量自难忘°
不思量自难忘° 2021-02-05 15:04

For a project I\'m currently working on I need to implement object versioning. Unfortunately I need to keep a full history of each object, so a single table solution like Paper

2条回答
  •  感情败类
    2021-02-05 15:22

    I've been using Vestal Versions, a rails gem/plugin that uses the memento pattern to create a history table, and it saves a diff of attributes in after_save and after_destroy callbacks.

    It also records when it was changed and increments a version number so you can rollback to a certain version or a version present at a certain date or time.

    I can then pull up an object like so:

    @user = User.last
    @user.versions.last.changes #=> {:name => ['Robert','Bob']}
    

    I'm a pretty big fan.

提交回复
热议问题