basecamp / audits1984

Auditing tool for Rails console sessions
MIT License
350 stars 26 forks source link

Config location #46

Closed colinbruce closed 1 year ago

colinbruce commented 1 year ago

Hi,

I'm trying to set up a proof of concept with audits1984 and console1984 on an existing service that does not use Devise.

I have (I think) followed the documentation from both gems and my config/application.rb now contains

require_relative "boot"

require "rails"
require "rails/all"

Bundler.require(*Rails.groups)

module MyAwesomeApplication
  class Application < Rails::Application
    config.middleware.use Rack::Attack
    config.load_defaults 7.0

    config.active_record.encryption.support_unencrypted_data = true
    config.console1984.ask_for_username_if_empty = true
    config.audits1984.auditor_class = ::AdminUser
    config.audits1984.auditor_name_attribute = :username
    config.audits1984.base_controller_class = ::Admin::AdminBaseController
    # <snip>
  end
end

But when starting a console I see config/application.rb:24:in '<class:Application>': uninitialized constant AdminUser (NameError)

I'm assuming it's being called before the objects are instantiated, is this the right location for the config block or should it be config/initialisers?

Also, does this only work with Devise objects?

colinbruce commented 1 year ago

So - I think I have worked out the location I now have a file named config/initializers/audits1984.rb containing

Audits1984.auditor_class = "AdminUser"
Audits1984.auditor_name_attribute = :username
Audits1984.base_controller_class = "Admin::AdminBaseController"

and rails consoles and servers now start! 🎉