Module CollectiveIdea::Acts::Audited::ClassMethods
In: lib/acts_as_audited.rb

Methods

Included Modules

CollectiveIdea::Acts::Audited::InstanceMethods

Public Instance methods

Configuration options

  • only - Only audit the given attributes
  • except - Excludes fields from being saved in the audit log. By default, acts_as_audited will audit all but these fields:
      [self.primary_key, inheritance_column, 'lock_version', 'created_at', 'updated_at']
    

    You can add to those by passing one or an array of fields to skip.

      class User < ActiveRecord::Base
        acts_as_audited :except => :password
      end
    
  • protect - If your model uses attr_protected, set this to false to prevent Rails from raising an error. If you declare attr_accessibe before calling acts_as_audited, it will automatically default to false. You only need to explicitly set this if you are calling attr_accessible after.
  • require_comment - Ensures that audit_comment is supplied before any create, update or destroy operation.
      class User < ActiveRecord::Base
        acts_as_audited :protect => false
        attr_accessible :name
      end
    

[Source]

     # File lib/acts_as_audited.rb, line 70
 70:         def acts_as_audited(options = {})
 71:           # don't allow multiple calls
 72:           return if self.included_modules.include?(CollectiveIdea::Acts::Audited::InstanceMethods)
 73: 
 74:           options = {:protect => accessible_attributes.nil?}.merge(options)
 75: 
 76:           class_inheritable_reader :non_audited_columns
 77:           class_inheritable_reader :auditing_enabled
 78: 
 79:           if options[:only]
 80:             except = self.column_names - options[:only].flatten.map(&:to_s)
 81:           else
 82:             except = [self.primary_key, inheritance_column, 'lock_version', 'created_at', 'updated_at']
 83:             except |= Array(options[:except]).collect(&:to_s) if options[:except]
 84:           end
 85:           write_inheritable_attribute :non_audited_columns, except
 86: 
 87:           if options[:comment_required]
 88:             validates_presence_of :audit_comment
 89:             before_destroy :require_comment
 90:           end
 91: 
 92:           attr_accessor :audit_comment
 93:           unless accessible_attributes.nil? || options[:protect]
 94:             attr_accessible :audit_comment
 95:           end
 96: 
 97:           has_many :audits, :as => :auditable, :order => "#{Audit.quoted_table_name}.version"
 98:           attr_protected :audit_ids if options[:protect]
 99:           Audit.audited_class_names << self.to_s
100: 
101:           after_create  :audit_create
102:           before_update :audit_update
103:           after_destroy :audit_destroy
104: 
105:           attr_accessor :version
106: 
107:           extend CollectiveIdea::Acts::Audited::SingletonMethods
108:           include CollectiveIdea::Acts::Audited::InstanceMethods
109: 
110:           write_inheritable_attribute :auditing_enabled, true
111:         end

[Validate]