Getting A Users Change History Using Audited Gem

Posted by Weston Ganger on October 17, 2015

Using the audited gem they didnt clearly define how to get a list of all of the changes / history the user has made. I wrote a method to do this

class User < ActiveRecord::Base
  #include Audited ###if your not using Rails or trying this on a different class that is not hooked up to audited yet

  def history
    Audited.audit_class.where(user_id: self.id).order(created_at: :desc)

Then it can be used like so:


Make that into an each and generate the history page for your user!

Posted in Rails and Tagged with rails audited 

Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts