如何在 Rails 控制台中查看 Rails 审计记录?

How do I view Rails audit records in my Rails console?

我正在使用 Rails 4.2.10 和经过审核的 gem,在我的 Gemfile 中定义如下......

gem "audited-activerecord", "~> 4.0"

我像这样在我的模型中激活它

class MyObject < ActiveRecord::Base
…
  audited

在Rails控制台中,如何查看特定的审计对象?我在我的控制台上试过了…

> Audit.all
NameError: uninitialized constant Audit
    from (irb):2
    from /usr/share/rvm/gems/ruby-2.4.5@cfs-web/gems/railties-4.2.10/lib/rails/commands/console.rb:110:in `start'
    from /usr/share/rvm/gems/ruby-2.4.5@cfs-web/gems/railties-4.2.10/lib/rails/commands/console.rb:9:in `start'
    from /usr/share/rvm/gems/ruby-2.4.5@cfs-web/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /usr/share/rvm/gems/ruby-2.4.5@cfs-web/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /usr/share/rvm/gems/ruby-2.4.5@cfs-web/gems/railties-4.2.10/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

但是得到上面的错误

我没想过要实际查询 audits table,我不得不查看源代码以了解如何执行此操作。

通常这应该适用于多个版本:

Audited.audit_class.count # => 9999

随着 audited > 4.2.2,AuditAudited 下得到了命名空间,它继承自 ActiveRecord::Basehere 是源代码。

Audited::Audit.count # => 99999