public
Description: Simple log utility for models. Add any number of optional arbitrary details fields, or user_id.
Clone URL: git://github.com/darcy/acts_as_loggable.git
darcy (author)
Wed Apr 23 08:16:23 -0700 2008
commit  e5bdb7faea7185f06a2e242a2924b01b279dd4be
tree    569599e3c0759b53c3066e6e0fa1d7792bde7bdb
parent  9746cf31222b999135b7f260a229d510d49793f5
name age message
file MIT-LICENSE Sat Apr 19 11:20:36 -0700 2008 initial commit [darcy]
file README Wed Apr 23 08:16:23 -0700 2008 Updated incredibly incorrect README instructions [darcy]
file init.rb Sat Apr 19 11:20:36 -0700 2008 initial commit [darcy]
directory lib/ Sat Apr 19 11:20:36 -0700 2008 initial commit [darcy]
README
== acts_as_loggable

This library adds simple logging to an ActiveRecord model.

Heavily inspired by acts_as_commentable. Did I say heavily?

== Usage

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

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"

Details are optional, also, pass a user_id to log the user_id, then o.logs.find_by_user(current_user), etc...


== Database

class CreateLoggable < ActiveRecord::Migration
  def self.up
    create_table "logs" do |t|
      t.string "message"
      t.integer "loggable_id"
      t.string "loggable_type"
      t.integer "user_id"
      t.timestamps
    end
    create_table "log_details" do |t|
      t.integer "log_id"
      t.string "label"
      t.text "detail"
    end
  end

  def self.down
    drop_table :logs
    drop_table :log_details
  end
end