Reputation: 286
Our model's whodunnit
value is a string - for example "22"
as in the User
with an id
of 22
.
The problem is we use both the User
and AdminUser
models to track whodunnit. As such, it is impossible to tell if a change was made by a User or, instead, by an AdminUser:
def user_for_paper_trail
current_user || current_admin_user
end
I'm a bit new to PaperTrail but worked my way through their docs and couldn't come up with any solutions. It might be a strange request, but I'd love for something like an arbitrary field which we could add a value for as a whodunnit type
, if that makes sense. Or a way to only track certain changes depending on the controller (which would work in this case since I'd only track changes which were made via the AdminPanel).
Thanks for any suggestions or guidance.
Upvotes: 0
Views: 2894
Reputation: 5802
PaperTrail is storing the id
because of one of these two reasons:
.id
on the value returned by your user_for_paper_trail
method.or
.id
on the results of your user_for_paper_trail
method.Since the User
or AdminUser
id
s are not universally unique, you should store a different value.
The whodunnit
value can be any string you decide. If you have a unique identifier that can be used to differentiate between Users
and AdminUsers
you should store that value.
I am thinking one of these options may solve your problem:
If email
is unique between the two user models, store the email instead of the id.
If email
is not unique, you could store a string that shows both the user model type and the id (e.g. 'User: 1'
and/or 'AdminUser: 1'
), then when you go to fetch the whodunnit
value you can parse the string for the user model and the id, then use that information as appropriate.
Read through how PaperTrail details how to find out who was responsible for a change and come up with a similar custom solution (or, another option).
Upvotes: 2