Search code examples
ruby-on-railsgitpaper-trail-gem

In PaperTrail, how to record a comment with each Version?


I am building a RoR based wiki. We use paper_trail gem to manage article versions, but viewing the changes to the article over time via the changeset method is a terrible user experience.

The best idea we have come up with is to require a git-commit-message-style comment before an editor can save changes. These commit messages would attach to the version of the article that is created when the article is updated.

Since the Version model is housed within the paper_trail gem, I am not sure how to associate the Versions table with my new commit_messages table s.t. a CommitMessage belongs_to a Version.


Solution

  • [I want] to require a git-commit-message-style comment before an editor can save changes

    You could add a comment column to your versions table. PaperTrail refers to this as "Storing Metadata".

    Metadata from Controllers

    You can also store any information you like from your controller. Override the info_for_paper_trail method in your controller to return a hash whose keys correspond to columns in your versions table.

    class ApplicationController
      def info_for_paper_trail
        { :ip => request.remote_ip, :user_agent => request.user_agent }
      end
    end
    

    If that doesn't work, the readme documents other ways to store metadata.