首页 > 解决方案 > 不适用于经过审核的 4.7 gem 更新模型

问题描述

我是 Rails 新手,我使用经过审核的 4.7 gem 用于我的 rails 应用程序来跟踪记录器。我不知道如何向审计表记录添加评论。谢谢你

宝石文件

gem "audited", "~> 4.7"

模型

class Client < ApplicationRecord

    audit

标签: ruby-on-railsloggingacts-as-audited

解决方案


# add to your Gemfile, and run bundle install to install it
gem "audited"

# install table for audited gem operation
rails generate audited:install
rails db:migrate

# open your model that you want to audited
class Client < ApplicationRecord
  audit
end
# restart rails server

# how to check the action 
@client = Client.first
@audits = @client.audits
if @audits
  @audits.each do |audit| 
    if audit.user
      audit.user.username
      audit.action
    end
  end              
end

推荐阅读