Created
November 15, 2018 18:04
Star
You must be signed in to star a gist
PaperTrail ActiveAdmin history pane
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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