0.0
No commit activity in last 3 years
No release in over 3 years
Model History is a simple gem that allows you to keep track of changes to specific fields in your Rails models using the ActiveRecord::Dirty module.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 3.2.11
>= 0
>= 0
 Project Readme

ModelHistory

Build Status

Model History is a simple gem that allows you to keep track of changes to specific fields in your Rails models using the ActiveRecord::Dirty module.

Installation

Add this line to your application's Gemfile:

gem 'model_history'

Install it using Bundler:

$ bundle install

Generate the Model History migration and migrate your database

$ rails generate model_history:migration
$ rake db:migrate

Usage

class Widget < ActiveRecord::Base
  has_model_history :name, :price, :creator => proc{ User.current_user }
  attr_accessible :name, :price
end

widget = Widget.last
widget.name # => "Box"
widget.name = "Heart Shaped Box"
widget.save
widget.model_history_records # => returns all changes to the widget
  
model_history = widget.model_history_records.last
model_history.old_value # => "Box"
model_history.new_value # => "Heart Shaped Box"

user   = User.find(123)
widget.model_history_records.created_by(user) 
  # => returns all changes to the widget performed by the specified user

class User < ActiveRecord::Base
  creates_model_history
end    

user = User.find(123)
user.model_history_records 
  # => returns changes made by the specified user

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request