Module: Challah::Audit
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/challah/audit.rb
Overview
The audit methods are included into ActiveRecord::Base automatically and add basic audit trail functionality for your models. Certain columns will be updated with the current user’s id if provided at save time.
For new records, the following fields will be updated if current_user
is provided:
-
created_by
-
created_user_id
For updating existing records, the following attributes will be updated:
-
updated_by
-
modified_by
-
updated_user_id
To save the user id that changed a record, just set the current_user
attribute of the model in your controller. For example:
class WidgetsController < ApplicationController
...
def update
@widget = Widget.find(params[:id])
@widget.current_user = current_user
@widget.update_attributes(params[:widget])
...
end
Instance Method Summary collapse
- #current_user=(value) ⇒ Object
- #current_user_id ⇒ Object
- #current_user_id=(value) ⇒ Object
- #initialize_dup(other) ⇒ Object
Instance Method Details
#current_user=(value) ⇒ Object
43 44 45 |
# File 'lib/challah/audit.rb', line 43 def current_user=(value) @current_user_id = (Object === value ? value[:id] : value) end |
#current_user_id ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/challah/audit.rb', line 51 def current_user_id unless @current_user_id @current_user_id = 0 end @current_user_id end |
#current_user_id=(value) ⇒ Object
47 48 49 |
# File 'lib/challah/audit.rb', line 47 def current_user_id=(value) @current_user_id = value end |
#initialize_dup(other) ⇒ Object
38 39 40 41 |
# File 'lib/challah/audit.rb', line 38 def initialize_dup(other) super clear_audit_attributes end |