0

I am new to rails and I used audited 4.7 gem for my rails application to track loggers. I have no idea how do I add a comment to audit table record. thank you

Gemfile

gem "audited", "~> 4.7"

Model

class Client < ApplicationRecord

    audit
Sandun Harshana
  • 721
  • 1
  • 13
  • 28

1 Answers1

1
# add to your Gemfile, and run bundle install to install it
gem "audited"

# install table for audited gem operation
rails generate audited:install
rails db:migrate

# open your model that you want to audited
class Client < ApplicationRecord
  audit
end
# restart rails server

# how to check the action 
@client = Client.first
@audits = @client.audits
if @audits
  @audits.each do |audit| 
    if audit.user
      audit.user.username
      audit.action
    end
  end              
end
widjajayd
  • 6,090
  • 4
  • 30
  • 41
  • thank you for answering. in my application audited working on a model. but only work with inserting and deleting a record. I want it to work with updating as well. In the default audit model there is a column as "comment". I want to add custom comment for logger. thank you – Sandun Harshana Feb 12 '19 at 23:04
  • my understanding audit by default is working also with updating, see # how to check the action part in my answer, but previously you should do one record create and update and then check the action through audit.action – widjajayd Feb 13 '19 at 00:46
  • Thanks, now it is working with updating also. How do I add a comment ? – Sandun Harshana Feb 13 '19 at 04:08
  • I answered your question above based from experience using audit gem to know who create/update the model, and I don't know how to use comment in audit, sorry – widjajayd Feb 13 '19 at 04:38