Class: Audit
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Audit
- Defined in:
- app/models/audit.rb
Overview
Audit
A model for handling audits. Expects a User model to be available.
Provides the following scopes:
-
desc- Orders bycreated_atDESC and thenidDESC -
recent- Returns the last 25 audits -
changes_on_attributes- Returns the audits with changes to the given attribute.
If you want to simply provide some notification of an event or a message. Assign to the messsage attribute instead of the change_set attribute.
Schema Information
Table name: audits
id :integer not null, primary key
audited_type :string(255) not null
audited_id :integer not null
user_id :integer not null
change_set :text not null
created_at :datetime not null
Constant Summary collapse
- MESSAGE =
"Message"
Class Method Summary collapse
-
.create_changes(model, change_set, user = nil) ⇒ Object
Create an Audit given the
model,change_setanduser.
Instance Method Summary collapse
-
#message ⇒ Object
Returns a message if this audit was a message.
-
#message=(message) ⇒ Object
Sets this audit to be a message with the given message.
Class Method Details
.create_changes(model, change_set, user = nil) ⇒ Object
Create an Audit given the model, change_set and user.
40 41 42 43 |
# File 'app/models/audit.rb', line 40 def self.create_changes(model, change_set, user=nil) user_id = user && user.id self.create!(:audited => model, :user_id => user_id, :change_set => change_set) end |
Instance Method Details
#message ⇒ Object
Returns a message if this audit was a message.
46 47 48 |
# File 'app/models/audit.rb', line 46 def self.change_set.has_key?(MESSAGE) && self.change_set[MESSAGE] end |
#message=(message) ⇒ Object
Sets this audit to be a message with the given message.
51 52 53 |
# File 'app/models/audit.rb', line 51 def () self.change_set = {MESSAGE => } end |