Skip to content

How to store PaperTrail whodunnit model name + ID #3137

@sedubois

Description

@sedubois

I managed to set up PaperTrail so that the whodunnit column stores User #1 when an app user does a change (configured via ApplicationController.user_for_paper_trail). I also managed to store info such as userid: console or userid: rake task_context:task_name via the PaperTrail initializer.

However I did not find how to do the same for changes done through my RailsAdmin panels as an administrator. If I use the config below, it only stores in the whodunnit column the administrator ID and not Administrator #1, which is in my view not clear enough (is it a user or an administrator ID?):

config.current_user_method(&:current_administrator)
config.audit_with :paper_trail, 'Administrator', 'PaperTrail::Version'

I tried the following too, but in that case the rails admin panel's "logout" button disappears:

config.current_user_method do
   "Administrator ##{current_administrator.id}"
end

I've defined a method user_for_paper_trail in my Admin::BaseController but it does not get called:

class Admin::BaseController < ApplicationController
  def user_for_paper_trail
    return unless defined?(current_administrator)
    "Administrator ##{current_administrator.id}"
  end
end

What is the clean way to tell RailsAdmin to let my user_for_paper_trail be called by papertrail?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions