导轨审计日志

发布于 2024-11-29 04:06:15 字数 197 浏览 0 评论 0原文

我正在使用 ruby​​ on Rails 3。 我想实现审计日志。 我已经经历了这个,但我想知道是否有任何方法可以实现相同的无需 使用任何 gem 或插件?

提前致谢!

I am working with ruby on rails 3.
I want to implement audit log.
I have gone through this, but I was wondering if there is any way to implement the same without using any gem or plugin?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

给妤﹃绝世温柔 2024-12-06 04:06:15

如果您想在控制器/操作级别进行审核,这里有一个简单的方法:

 class BankController < ActionController::Base
    before_filter :audit

    private
      def audit
      # record the action and parameters in an audit log
      end
 end

通过继承,您也可以在其他控制器上进行审核:

class VaultController < BankController
  before_filter :verify_credentials

  private
    def verify_credentials
      # make sure the user is allowed into the vault
    end
 end

在第二种情况下,:audit 将在 :verify_credentials 之前运行。

过滤器的详细信息请参见此处

如果您希望使用 active_records 在数据库级别进行审核,你可以使用观察者。 详细信息请参见此处

If you want audit at the controller/action level, here is a simple way to do it:

 class BankController < ActionController::Base
    before_filter :audit

    private
      def audit
      # record the action and parameters in an audit log
      end
 end

And with inheritance, you get this accross other controllers as well:

class VaultController < BankController
  before_filter :verify_credentials

  private
    def verify_credentials
      # make sure the user is allowed into the vault
    end
 end

In the second case, :audit will be run before :verify_credentials.

Filters are detailed here

If you want audit at the database level with active_records, you can use Observers. Detailed here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文