Skip to content

Instantly share code, notes, and snippets.

@ccabot
Created January 26, 2011 18:58
Show Gist options
  • Save ccabot/797212 to your computer and use it in GitHub Desktop.
Save ccabot/797212 to your computer and use it in GitHub Desktop.
patch paper_trail to work with RailsAdmin
require "paper_trail/version"
# Make PaperTrail's Version class quack like RailsAdmin's History
class Version
def username ; whodunnit && User.find(whodunnit).try(:email) || whodunnit ; end
def message ; "#{event} #{item_type} id #{item_id}" ; end
def table ; item_type ; end
def updated_at ; created_at ; end
# the count(*) that we select in the :number attribute comes back
# from postgres as a string, so we need to "to_i" it
def number ; super.to_i ; end
def month ; super.to_i ; end
# Make Version look like History when it gets JSON-serialized.
def as_json(*a)
{"history" => {"record_count" => number, "month" => month, "year" => year}}.as_json(*a)
end
end
@miguelsan
Copy link

Beware that this gist asumes (line 6) that you have a user model called User who is been identified by his email address. Your configuration may vary there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment