collectiveidea / audited

Audited (formerly acts_as_audited) is an ORM extension that logs all changes to your Rails models.
MIT License
3.38k stars 662 forks source link

Audits by user? #111

Open splurgy-michi opened 12 years ago

splurgy-michi commented 12 years ago

Is there a simple way to get audit entries by user? As in the value in the user_id column?

The current "hack" looks like this:

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

Is this the only way?

dougc84 commented 11 years ago

I know this is a couple months old, but I did this in a model:

Audit = Audited::Adapters::ActiveRecord::Audit
class Audit
  # my custom methods
end

That way, I can access it with Audit.whatever, AND I can add my own custom methods. Works well. You could probably use class inheritance as well, but I haven't tried it:

class Audit < Audited::Adapters::ActiveRecord::Audit
  # whatevers
end
tomprats commented 9 years ago

@dougc84 :+1: Exactly something I want to do, but doesn't seem to work if I use associated_audits. I get an undefined method error for Audited::Adapters::ActiveRecord::Audit instead of it actually using me Audit class

dougc84 commented 9 years ago

@tomprats you could always write a class and have it extend Audited::Adapters::ActiveRecord::Audit from an initializer

tomprats commented 9 years ago

@dougc84 How do I have associated_audits to use that extended class then? Right now I'm just trying to add methods to the library's Audited::Adapters::ActiveRecord::Audit class but I'm not sure exactly how to do that. I've added my audit.rb file to the lib directory, configured the application.rb to autoload it, but I haven't been able to add anything to the Audit class (even trying to nest it in it's modules)

tomprats commented 9 years ago

Wow, I actually got it to work successfully, what took me so long was something with postgres being setup incorrectly.