Use callbacks to determine model field changes?


#1

What’s the best way to examine what fields on a model are changing?
Would you use a callback to do that and how?

I guess the simplest example of this is how lighthouseapp documents
changes that a person makes to a ticket:

Milestone changed from “2.x” to “3.0”

State changed from “new” to “open”

How could I accomplish the same thing?


#2

Take a look at
ActiveRecord::Dirtyhttp://api.rubyonrails.org/classes/ActiveRecord/Dirty.html

Benjamin C.
http://railskits.com/ - Ready-made Rails code
http://catchthebest.com/ - Team-powered recruiting
http://www.bencurtis.com/ - Personal blog


#3

If you’re on Rails >= 2.1, you can track attribute changes:

http://api.rubyonrails.org/classes/ActiveRecord/Dirty.html

You might also like Ryan B.’ screencast on the topic:

http://railscasts.com/episodes/109-tracking-attribute-changes

Regards,
Craig


Craig D.
Mutually Human Software
http://mutuallyhuman.com


#4

Thanks for the help guys.

However, I’ve now hit the trap where I need session data in the
observer (who is changing the model)…