Skip to content

Instantly share code, notes, and snippets.

@RobinDaugherty
Created November 15, 2018 18:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save RobinDaugherty/e2da72904ab1a53e046123bb74cba456 to your computer and use it in GitHub Desktop.
PaperTrail ActiveAdmin history pane
ActiveAdmin.register DeviceState do
# ...
action_item :history, only: :show do
link_to 'History', [:history, :admin, resource]
end
member_action :history do
render "layouts/history"
end
# ...
end
panel "History" do
table_for resource.versions do
column "At", &:created_at
column "Action", &:event
column "By" do |v|
user = User.find_by(id: v.whodunnit)
if user
auto_link(user)
else
span "nobody"
end
end
column "" do |v|
if v.changeset.empty?
else
table style: 'margin: 0' do
thead do
tr do
th "Changed"
th "From"
th "To"
end
end
tbody do
v.changeset.each do |(field_name, c)|
next unless field_name != 'updated_at'
tr do
td field_name
td c.first
td c.last
end
end
end
end
end
end
end
end
# If using CanCan. Use a similar thing to authorize the "history" action if using Pundit for example.
# ...
can %i[read history], ResourceName
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment