ActiveRecord manages your updated_at columns for you, updating the timestamp when your records change. This gem provides similar, but more granular functionality: in addition to a table-wide updated_at column, you can have additional timestamp columns that track when specific columns change.
gem install column_timestamps
Load the gem using Rails' 2.1+ gem support. In environment.rb:
Usage is pretty simple:
Create a new datetime column using the naming convention <column>_updated_at.
Include ColumnTimestamps in your model.
# in a migration... create_table :users, :force => true do |t| t.string :email_address t.string :name t.string :state t.datetime :state_updated_at t.timestamps end # Model... class User < ActiveRecord::Base include ColumnTimestamps end
Anytime the state attribute of a user record is changed, the state_updated_at timestamp will be updated to reflect that.
column_timestamps relies upon the dirty attributes functionality introduced to ActiveRecord in version 2.1. It works on any version since 2.1, including 3.0.0.beta4. It works on ruby 1.8.6], 1.8.7 and 1.9.1.
Note on Patches/Pull Requests
Fork the project.
Make your feature addition or bug fix.
Add tests for it. This is important so I don't break it in a future version unintentionally.
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
Send me a pull request. Bonus points for topic branches.
Copyright © 2009-2010 Myron Marston. See LICENSE for details.