1

I'm using the gem audited in my rails app, and I'm wondering if it's possible to add auditing of actions other than create, update and destroy..?

ALternatively, maybe someone can point me to another gem that supports this, since I need to track all kinds of access to the app.

Thanks

nourza
  • 2,215
  • 2
  • 16
  • 42
henrik242
  • 366
  • 4
  • 11
  • 1
    here is a list of gems with similar functionality, maybe it can be useful for you: http://www.plugingeek.com/categories/activerecord-versioning-and-auditing-ruby – Nezir Sep 30 '18 at 20:08

1 Answers1

1

I found a way around the issue, that, although not ideal for all, meets the requirements for my little application.

I added a class Audit that just looks like this:

class Audit < ActiveRecord::Base
  belongs_to :user
end

And then I added this to the ApplicationController

after_action only: :show do |c|
  a = Audit.new
  a[:auditable_id] = params[:id]
  a[:auditable_type] = self.class.to_s.gsub(/^(.+)sController/, '\1')
  a[:user_id] = current_user.id
  a[:user_type] = 'User'
  a[:action] = 'show'
  a[:comment] = "url fullpath: #{request.original_fullpath}"
  a[:remote_address] = request.remote_ip
  a[:request_uuid] = request.uuid

  a.save
end
henrik242
  • 366
  • 4
  • 11