Audit, view audits owned by the user

I use audited to track changes for a model called Page . I would like to be able to find all the audits associated with a specific user (via user_id in the audit table).

How can i do this? So far, the only way I have found access to the Audit model is as follows:

 @audits = Audited::Adapters::ActiveRecord::Audit.all 

It doesn't seem like it's the right way to do something.

Trying @audits = Audit.all gives an Uninitialized constant error.

Is there a more graceful way to interact with the models provided by precious stones?

+7
source share
3 answers

Maybe something like

include Audited::Adapters::ActiveRecord::Audit

and then you can do

@audits = Audit.all

?

I think this should work ... Or better yet:

include Audited

+6
source

You can access all audit records using

 Audited::Audit.all 

I got the result when I typed

 Audited.audit_class 

DEPARTMENT WARNING: audit_class is deprecated and will be removed from Rails 5.0 (Audited.audit_class is now always audited. The method will be deleted.).

+1
source

I know that this is not an effective way to do this, but that’s how I do it.

In the Rails console, I get a report that I know is being checked.

@page = Page.first

Then I get this first audit of the record.

@audit = @page.audits.first

Then you can call #class on @audit

@audit.class

Result:

 Audited::Adapters::ActiveRecord::Audit(id: integer, created_at: datetime, updated_at: datetime, auditable_id: integer, auditable_type: string, user_id: integer, user_type: string, username: string, action: string, audited_changes: text, version: integer, comment: string, full_model: text, remote_address: string, associated_id: integer, associated_type: string, request_uuid: string) 

Audited::Adapters::ActiveRecord::Audit is the name of the class that you can use in your search.

audits = Audited::Adapters::ActiveRecord::Audit.where(:user_id => 8675309)

0
source

All Articles