ruby-on-railspaper-trail-gem

How to capture custom metadata in PaperTrail only on create event type and work normally for update and destroy


has_paper_trail on: [:create], meta: { object: "custom data" }

this works only for create event

has_paper_trail on: [:create], meta: { object: "custom data" }
has_paper_trail on: [:update, destroy]

tried this way for other events apart from create but second call overrides the first here

i need custom data only incase of create and and other events should work normally


Solution

  • Try using a lambda that only returns data for meta when the object is a new record...

    has_paper_trail on: [:create, :update, :destroy], 
                    meta: Proc.new { |t| t.new_record? ? { object: "custom data" } : nil }