Skip to main content

Record History

paper_trail_associations adds the versions of associated records to the parent record's History page, so one timeline shows changes across the parent and its children.

Quick example​

app/models/application_record.rb
class ApplicationRecord < ActiveRecord::Base
include CmAdmin::PaperTrailAssociations
primary_abstract_class
end
app/models/production_order.rb
has_paper_trail
paper_trail_associations :po_items, :attachments

Setup​

Add CmAdmin::PaperTrailAssociations to your host app's ApplicationRecord:

class ApplicationRecord < ActiveRecord::Base
include CmAdmin::PaperTrailAssociations
primary_abstract_class
end

In the model that needs associated history, call paper_trail_associations with the associations to include:

has_paper_trail
paper_trail_associations :po_items, :po_parts, :po_pieces, :release_orders, :ro_pieces, :attachments

Note:

  • has_paper_trail must be added to the model as well.
  • In the example above, the parent model has has_many :po_items, PoItem has has_many :po_parts, and so on.

Example associations:

has_many :po_items, inverse_of: :production_order, dependent: :destroy
has_many :po_parts, through: :po_items
has_many :po_pieces, through: :po_parts
has_many :release_orders, dependent: :destroy
has_many :ro_pieces, through: :release_orders
has_many :attachments, as: :attachable, dependent: :destroy