Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I temporarily disable PaperTrail when reifying a version?

I am using paper_trail for undo/redo functionality in my site and am having a problem when I call reify.save on a version in that on save and new PaperTrail::Version gets created.

Is there a way to turn off PaperTrail during the saving of a reified object?

I understand that PaperTrail.enabled = false is possible, but I don't want other changes being made a the same time to not be recorded.

My ideal solution would be something along the lines of:

PaperTrail.disable { version.reify.save }

like image 465
turbogeek421 Avatar asked Jan 05 '23 08:01

turbogeek421


1 Answers

I once accomplished something similar by mixing in something like this:

def without_papertrail
  PaperTrail.disable
  yield if block_given?
  PaperTrail.enable
end

Then you can do something similar to your objective

without_papertrail { version.reify.save }
like image 60
AndyV Avatar answered Jan 07 '23 22:01

AndyV