Audit Trail

A complete, immutable record of system activity
<%= form_with url: admin_portal_audit_trails_path, method: :get, local: true do |f| %>
<%= f.label :user_id, "User", class: "form-label text-secondary small" %> <%= f.select :user_id, options_from_collection_for_select(@users, :id, :display_name, params[:user_id]), { include_blank: "All users" }, class: "form-select form-select-sm slim-select", data: { controller: "slim-select", slim_select_target: "select" } %>
<%= f.label :entity, "Entity", class: "form-label text-secondary small" %> <%= f.select :entity, options_for_select(@entities.map { |e| [e.titleize, e] }, params[:entity]), { include_blank: "All entities" }, class: "form-select form-select-sm rounded-pill" %>
<%= f.label :action_type, "Action", class: "form-label text-secondary small" %> <%= f.select :action_type, options_for_select(%w[create update delete show approve reject send_registration_link], params[:action_type]), { include_blank: "All actions" }, class: "form-select form-select-sm rounded-pill" %>
<%= f.label :start_date, "From", class: "form-label text-secondary small" %> <%= f.date_field :start_date, value: params[:start_date], class: "form-control form-control-sm rounded-pill" %>
<%= f.label :end_date, "To", class: "form-label text-secondary small" %> <%= f.date_field :end_date, value: params[:end_date], class: "form-control form-control-sm rounded-pill" %>
<%= f.submit "Apply", data: { turbo: false }, class: "btn btn-primary btn-sm rounded-pill px-4" %> <%= link_to "Clear", admin_portal_audit_trails_path, data: { turbo: false }, class: "btn btn-warning btn-sm rounded-pill px-4" %>
<% end %>
<% @audit_trails.each do |log| %> <% end %>
Time User Action Entity Description IP / Device Name Details
<%= log.occurred_at.strftime("%b %d, %Y · %H:%M") %> <%= log.user&.display_name || "System" %> <% badge_class = case log.controller_action when "create" then "bg-success-subtle text-success" when "update" then "bg-warning-subtle text-warning" when "delete" then "bg-danger-subtle text-danger" when "show" then "bg-primary-subtle text-primary" else "bg-secondary-subtle text-secondary" end %> <%= log.controller_action.titleize %> <%= log.controller_name %> <%= log.description %>
<%= log.ip_address %>
<% if log.device.present? %>
<%= log.device.name %>
<% end %>
<% if log.metadata["changes"].present? %>
    <% log.metadata["changes"].each do |k, v| %>
  • <%= k.to_s.humanize %>: <%= v.join(" → ") rescue v %>
  • <% end %>
<% else %> <% end %>