Class: Admin::HistoryController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- BaseController
- Admin::HistoryController
- Defined in:
- lib/generators/open_loam/install/templates/admin/history_controller.rb
Overview
A record's change history (OpenLoam::AuditRecord) with one-click Undo (L-704). Undo applies the inverse of a change and records ITSELF as an audit, so undoing an "undo" entry is redo — no separate redo action. Reading needs read on the record; undoing needs update (the same gate as editing it).
Constant Summary
Constants included from Pagination
Instance Method Summary collapse
Methods inherited from BaseController
Methods included from Pagination
Instance Method Details
#index ⇒ Object
11 12 13 14 15 16 |
# File 'lib/generators/open_loam/install/templates/admin/history_controller.rb', line 11 def index (policy_for(@record), :read?) @audits = OpenLoam::AuditRecord .where(auditable_type: @record.class.name, auditable_id: @record.id) .order(id: :desc).limit(100) end |
#undo ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/generators/open_loam/install/templates/admin/history_controller.rb', line 18 def undo (policy_for(@record), :update?) audit = OpenLoam::AuditRecord.find(params[:id]) OpenLoam::Undo.undo(audit, policy: policy_for(@record)) redirect_to admin_history_path(type: @record.class.name, record_id: @record.id), notice: "Change undone." rescue OpenLoam::Undo::NotUndoableError => error redirect_to admin_history_path(type: @record.class.name, record_id: @record.id), alert: error. end |