Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Simple log utility for models. Add any number of optional arbitrary details fields, or user_id.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 generators
Octocat-spinner-32 lib
Octocat-spinner-32 .gitignore
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 init.rb
README.rdoc

acts_as_loggable

This library adds logging to an ActiveRecord model.

Inspired by acts_as_commentable.

Usage

class Order < ActiveRecord::Base
  acts_as_loggable
  ...
end

1. Simple

o = Order.find(:first)
o.logs << Log.new(:message => "Credit Card Aprroved")
o.logs.first.message # => "Credit Card Aprroved"

2. With some details

o = Order.find(:first)
log = Log.new(:message => "Credit Card Aprroved")
log.details = [["transaction_id","TX1234"],["test",false],["foo","bar"]]
o.logs << log
o.logs.first.message # => "Credit Card Aprroved"
o.logs.first.details.first.label # => "transaction_id"
o.logs.first.details.first.detail # => "TX1234"

3. Adding a grouping type and an Owner

o = Order.find(:first)
o.logs << Log.new(:message => "Credit Card Aprroved", :group => 'card_approval', :user => User.find(:first), :owner => Store.find(:first))
o.logs.find_by_user(current_user)
o.logs.find_by_owner(current_store)
o.logs.find_by_group('card_approval')

Database

script/generate acts_as_loggable_migration
rake db:migrate
Something went wrong with that request. Please try again.