Created
          January 26, 2011 18:58 
        
      - 
      
- 
        Save ccabot/797212 to your computer and use it in GitHub Desktop. 
    patch paper_trail to work with RailsAdmin
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | 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 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
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.