Rails

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)
  end
end

Then it can be used like so:


@user.history

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


Posted in Rails and Tagged with rails audited 


Want me to help develop your next project or application?

Contact Us

Specializing in Ruby-on-Rails, Javascript, Multi-Platform Electron Desktop Apps and Hybrid Cordova Mobile Apps.

Recommended Posts