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

How To Skip PaperTrail Version on ActiveRecord Callback


Currently, I've implemented a Rails Data Auditing app using PaperTrail. I've added a new version for every create, update and destroy actions.

The thing is that, I have an after_create callback in my model in which I want the PaperTrail to ignore it.

For now, when I create a new record, there are two versions are created. One is of the create event, and other one is of the update event of my callback.

What I want is to just one version to be created here, a version of the create event.

To be specific, my callback is just to add a slug, an alias is, to my record in which I do not want to show such this change to the user.

I wonder if there is a way to do so.

Any suggestions are appreciated.

Thanks,


Solution

  • I think you can make use of without_versioning, which

    Executes the given method or block without creating a new version

    user.without_versioning { |obj| obj.update_attributes(attribute: 'new_value') }