= Audit
Add this line to your application's Gemfile:
gem 'audit', github: 'runeleaf/audit'
Download and install by running:
> bundle install
> rails g audit:migration
> rails g audit:migration
> rake db:migrate
Model:
class Post < ActiveRecord::Base
audit_log
...
end
method:
Post.transcribe user: current_user, view_name: 'test', action_name: 'posts#create', crud_name: 'search'
Post.auditable #=> [#<Audit::AuditLog>]
Callbacks:
class Post < ActiveRecord::Base
audit_log force: true
...
end
save or create:
post = Post.new title: 'test'
post.save
post.audits #=> [#<Audit::AuditLog>]
update:
post = Post.first
post.save
post.audits #=> [#<Audit::AuditLog>, #<Audit::AuditLog>]
post.transcribe user: current_user, view_name: 'test', action_name: 'posts#update', crud_name: 'update'
post.audits #=> [#<Audit::AuditLog>, #<Audit::AuditLog>, #<Audit::AuditLog>]
destroy:
post = Post.first
post.destroy
post.audits #=> [#<Audit::AuditLog>, #<Audit::AuditLog>, #<Audit::AuditLog>, #<Audit::AuditLog>]