1
  • ruby "2.6.3"
  • gem "audited", "4.8.0"
  • gem "pg", "0.18.4"

I need to be able to:

  1. search revisions by date range
  2. search all the audits by date range then get the latest of each record

Currently the record's revision has nil for created_at and updated_at columns. I am able to report.revision_at(yesterday) but not date range

So I tried looking into audits. I am grouping them by auditable_id which looks it's group by records. Then I get the latest. But this only shows me what was changed:

 Audited::Audit.where(auditable_type: "Report")
   .where(created_at: 7.months.ago..1.month.ago)
   .group_by(&:auditable_id)
   .map { |_, v| v.sort_by(&:created_at).max }

Ideally I want to do something like this to get the latest revisions between the time range I am looking for

Reports.all.map do |report|
  report.revisions
    .where(created_at: 7.months.ago..1.month.ago)
    .sort_by(&:created_at).max
end

Here's what I get when I look at report.revisions. As you see created_at comes back nil when looking at the revisions:

[#<Report:0x000
  id: "100f5d9d-",
  device: "1-device-118",
  advisor: "system",
  created_at: nil,
  updated_at: nil>]

original record in Report table does have created_at and updated_at:

#<Report:0x0
 id: "100f5d9d-",
 device: "1-device-118",
 advisor: "system",
 created_at: Fri, 07 Dec 2018 03:15:37 UTC +00:00,
 updated_at: Fri, 07 Dec 2018 03:15:37 UTC +00:00>
Sarah A
  • 1,185
  • 12
  • 27
  • It is listed as an issue, this thread may help you https://github.com/collectiveidea/audited/issues/497#issuecomment-510414598 – Ines Feria Mar 22 '20 at 18:58

0 Answers0