Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add auditing of actions other than create, update and destroy with gem audited

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

like image 490
henrik242 Avatar asked Dec 27 '25 22:12

henrik242


1 Answers

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
like image 52
henrik242 Avatar answered Dec 30 '25 15:12

henrik242



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!