I am new to rails. I want to track the versions of my record using paper_trail gem but I am not able to do so when I use the update_columns method. I think overriding the update_columns method may help me but I don't know how exactly should I write the code?
Asked
Active
Viewed 500 times
1 Answers
1
How to skip all callbacks except paper-trail when updating an ActiveRecord model using update_column method? .. I use the update_columns method.
Per the Rails docs, the update_columns
method skips callbacks. This includes the callbacks installed by PT.
I am new to rails. ... I think overriding the update_columns method may help me ..?
If you're new to rails, you should not override core rails methods.
Solutions
In descending order of preference:
- Normally, I'd recommend using
update
instead ofupdate_columns
. But, you want to skip a proper subset of callbacks. - You can
touch
the record, and PT will record aVersion
in which onlyupdated_at
changed. If you only needobject
and notobject_changes
, this is sufficient. - You can use
PaperTrail::Version.create
just like any other model. This is public API, but you're responsible for passing the correct attributes. - You can use
PaperTrail::RecordTrail#record_update
. This is private API and is subject to change at any time without warning.

Jared Beck
- 16,796
- 9
- 72
- 97