Skip to content

stevepolitodesign/action_text_paper_trail

Repository files navigation

README

Explores how to add paper_trail to Action Text.

Because ActionText::RichText is stored in the "action_text_rich_texts" table, it's not versioned by default, even if the associated record uses has_paper_trail.

One solution is to add has_paper_trail to ActionText::RichText by via a Concern through an initializer.

# config/initializers/action_text.rb
Rails.application.config.to_prepare do
  ActionText::RichText.include HasPaperTrail
end

# app/models/concerns/has_paper_trail.rb
module HasPaperTrail
  extend ActiveSupport::Concern

  included do
    has_paper_trail
  end
end

# app/models/message.rb
class Message < ApplicationRecord
  include HasPaperTrail

  has_rich_text :content
end

message = Message.create!(content: "Version 1")
message.update!(content: "Version 2")
message.content.versions.last.reify.body.to_plain_text
# => Version 1

Local Setup

Run ./bin/setup

About

Add paper_trail to Action Text

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published