I want to create the following method for paper_trail versions:
def user
User.find self.whodunnit.to_i
end
So that I can access a version's user naturally in my app as if it has a belongs_to
relation.
Where should I put this function (folder and file name) in order to override / add it to paper_trail's version model?
You could put this in an initializer (e.g.,
config/initializers/paper_trail.rb
) that opens thePaperTrail::Version
class:You'll want to confirm that your
Version
model isPaperTrail::Version
; older versions of the gem use justVersion
. In that case, just remove the outer module statement.You could also create a custom class inheriting from
Version
, and specify that in yourhas_paper_trail
call. For example (from the README):