From 6913420e9846d953b4ea7f6f997270d56a981c18 Mon Sep 17 00:00:00 2001 From: ruzmanov Date: Fri, 23 Jan 2015 20:16:37 +0300 Subject: [PATCH] option for mass import --- app/models/chrno_audit/audit_observer.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/chrno_audit/audit_observer.rb b/app/models/chrno_audit/audit_observer.rb index 42e5a66..90cb593 100644 --- a/app/models/chrno_audit/audit_observer.rb +++ b/app/models/chrno_audit/audit_observer.rb @@ -40,7 +40,7 @@ def after_destroy( entity ) # @param [ActiveRecord::Base] entity # @param [#to_s] action # - def create_audit_record!( entity, action ) + def create_audit_record!( entity, action, params = {} ) # Ничего не делаем, если аудит данного действия отключён return unless entity.class.auditable_actions.include? action @@ -51,13 +51,16 @@ def create_audit_record!( entity, action ) # Ничего не делаем если модель не изменилась return if entity.class.auditable_options[ :ignore_empty_diff ] && changes_to_store.empty? && action != :destroy - ChrnoAudit::AuditRecord.create do |record| + audit_record = ChrnoAudit::AuditRecord.new do |record| record.action = action.to_s record.auditable = entity record.diff = changes_to_store record.initiator = context.delete( :initiator ) || context.delete( :current_user ) record.context = context end + + audit_record.save! unless params[:nosave] + audit_record end ##