Storing an events log book.
Add this line to your application's Gemfile:
gem "log_book"
As the Model should be loaded after ActiveReccord has established the connection you have to add this:
# config/application.rb
config.after_initialize do
require "log_book/event"
end
rails generate log_book:migration
rake db:migrate
rails generate acts_as_taggable_on:migration
rake db:migrate
In any point:
LogBook.event(<who executes the action>, <over which object>, <text>, <list of tags>)
For example:
LogBook.event(current_user, item, "Item canceled", [:purchase, :canceled])
class MyModel < ActiveRecord::Base
log_book
end
MyModel.create! # => LogBook created
my_model.save! # => LogBook created
my_model.destroy! # => LogBook created
If you want to include who executes the action use the special attribute log_book_historian
:
my_model.log_book_historian = current_user
my_model.save!
Beta version but already used in production environments