Search code examples
rubyruby-on-rails-3loggingobserver-patternauditing

Rails audit system with both ActiveResource and ActiveRecord


I have a huge project with both of ActiveRecord and ActiveResource models. I need to implement logging of user activity with these models and also to log changes of model attributes (save object state or somthing like that). Changes can made by users or cron rake tasks.

I also must have possibility to search any data by date , any field ..etc

Will be nice also to generate readable messages with last activity , for example

  • User Bob change his password to * and email to ** at 2011-08-12 08:12
  • Staff Jeff added new partner: Company name at 2011-08-12 08:13
  • Admin Jack deleted product : Product name at 2011-09-12 11:11
  • Client Sam ordered new service : Service name at 2011-09-12 11:12

Does anybody implement such logging? Ideas? Advices?

should I use gems or can I do all the logic with observers not changing models?


I liked gem https://github.com/airblade/paper_trail can anybody say how can I make it work with activeresource ?


Solution

  • The acts_as_audited gem should work well for you:
    https://github.com/collectiveidea/acts_as_audited

    And as far as ActiveResource is considered, it will also be a model in some other application. You can use the gem at the server side, and you don't need to audit it at the client side. All the CRUD operations using ActiveResource would finally translate to CRUD operations on the ActiveRecord (on server side).

    So probably you need to look at it from a distance, and the same solution would apply in both the cases, but at different places.