Track Changes
Installation
Migration
class CreateTrackChangesTables < ActiveRecord::Migration
def change
create_table :track_changes_snapshots do |t|
t.references :record, :polymorphic => true
t.text :state
t.
end
create_table :track_changes_diffs do |t|
t.references :record, :polymorphic => true
t.text :from
t.text :to
t.string :action
t.string :changes_by
t.
end
end
end
Usage
In your model
class Person < ActiveRecord::Base
tracks_changes # may also pass an options hash
end
Options
By default all model attributes are tracked, except the primary_key, usually id, created_at, and updated_at.
:onlyaccepts a field name or array of field names to track instead of the default fields:exceptaccepts a field name or array of field names to ignore:methodsaccepts a field name or array of field names to track in addition to the default fields:track_timestampsaccepts a boolean, enabling or disabling tracking ofcreated_atandupdated_at:track_primary_keyaccepts a boolean, enabling or disabling tracking of the model's primary key