Reputation: 1147
I've integrated paper_trail with a Project Model.
Normal Flow:-
Whenever project Record in model gets updated, a new version with changes gets created in Versions table.
Requirement:-
Whenever any project gets updated, rather than updating project record itself in projects model, i want to create a new Version Record. is there any way to do it ?
I'm using Rails 5.1.6.2, paper_trail (10.3.0)
Upvotes: 2
Views: 1300
Reputation: 49
We also have this flow in our app where a user can edit a record, but the edits have to be approved or rejected before going live. So we use PaperTrail as intended, but then immediately rollback the changes and created a workflow for the approval/rejection that reinstates them or not.
Upvotes: 0
Reputation: 17528
I'd try using PaperTrail::Events::Update
, though it's not public API (it may change at any time without warning)
project.name = 'new name'
update = PaperTrail::Events::Update.new(project, ....)
PaperTrail::Version.create!(update.data)
Again, this is not public API, so you will void your warranty :)
Whenever any project gets updated, ..
I'd put this in my ProjectController#update
action only. You could use a model callback like before_save
if you really have to, and throw :abort
to halt the callback chain, but you'll have to work around the implicit transaction.
Upvotes: 1