https://github.com/work-design/rails_audit
记录数据变动,可恢复,可审核
https://github.com/work-design/rails_audit
Last synced: about 1 year ago
JSON representation
记录数据变动,可恢复,可审核
- Host: GitHub
- URL: https://github.com/work-design/rails_audit
- Owner: work-design
- Created: 2015-09-19T03:00:41.000Z (almost 11 years ago)
- Default Branch: main
- Last Pushed: 2025-04-09T03:43:24.000Z (about 1 year ago)
- Last Synced: 2025-04-09T04:27:30.439Z (about 1 year ago)
- Language: Ruby
- Homepage:
- Size: 318 KB
- Stars: 2
- Watchers: 5
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.en.md
Awesome Lists containing this project
README
# RailsAudit
Unlike [audited](https://github.com/collectiveidea/audited) and [paper_trail](https://github.com/airblade/paper_trail) etc. These model audit tools use model callbacks to record every changes.
`rails_audit` record ActiveRecord Model changes in Controllers, it will record context with model changes:
1. controller
2. action
3. request.remote_ip
4. current_operator
5. any other info you want to record..
### Model style audit VS controller style audit
| Model Style Audit | Controller style Audit |
| --- | --- |
| Record every changes | Record only when you marked |
| use model callback, can skip by the data persistence not commit callback | No model callback |
| use thread variables delivery state from controller to model | Just add variables you can get in controller |
## Usage
### in Model
1. include Audited
```ruby
class User < ActiveRecord::Base
include RailsAuditExt::Audited
end
```
### in Controller
```ruby
class UsersController < ApplicationController
include RailsAudit::Application
# use after action, will auto record changes by use saved_changes api
after_action only: [:update, :create, :destroy] do
mark_audits(:@user, :@role, note: 'note something!', extra: { client_headers: request.headers })
end
end
```
### in View
```ruby
link_to 'Audits', audits_path('User', user.id)
```
## 许可证
License 采用 [LGPL License](https://opensource.org/licenses/LGPL-3.0).