class Product < ApplicationRecord
include Audited
audited
end
class AddAuditedToProducts < ActiveRecord::Migration[6.0]
def change
add_column :products, :audited, :jsonb, default: {}, null: false
end
end
def destroy
@product = Product.find(params[:id])
@product.audit_comment = "Deleted by #{current_user.email}"
@product.destroy
respond_to do |format|
format.html { redirect_to products_path, notice: "Product was successfully deleted." }
format.json { head :no_content }
end
end
#
这样,当删除记录时,就会在审计记录中添加注释。