# Use callbacks to determine model field changes?

**URL:** <https://www.ruby-forum.com/t/use-callbacks-to-determine-model-field-changes/168942>\
**Category:** Rails\
**Created:** [May 27, 2009, 4:26pm UTC](https://www.ruby-forum.com/t/use-callbacks-to-determine-model-field-changes/168942 "2009-05-27T16:26:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![coolmenu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@coolmenu](https://www.ruby-forum.com/u/coolmenu)\
**Post date:** [May 27, 2009, 4:26pm UTC](https://www.ruby-forum.com/t/use-callbacks-to-determine-model-field-changes/168942/1 "2009-05-27T16:26:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![coolmenu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@coolmenu](https://www.ruby-forum.com/u/coolmenu)\
**Post date:** [May 27, 2009, 4:32pm UTC](https://www.ruby-forum.com/t/use-callbacks-to-determine-model-field-changes/168942/2 "2009-05-27T16:32:15Z")

</div>

## Take a look at ActiveRecord::Dirty[http://api.rubyonrails.org/classes/ActiveRecord/Dirty.html](http://api.rubyonrails.org/classes/ActiveRecord/Dirty.html)

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

---

<div class="post-metadata">

**Author:** ![coolmenu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@coolmenu](https://www.ruby-forum.com/u/coolmenu)\
**Post date:** [May 27, 2009, 4:32pm UTC](https://www.ruby-forum.com/t/use-callbacks-to-determine-model-field-changes/168942/3 "2009-05-27T16:32:16Z")

</div>

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

[http://api.rubyonrails.org/classes/ActiveRecord/Dirty.html](http://api.rubyonrails.org/classes/ActiveRecord/Dirty.html)

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

> **[\#109 Tracking Attribute Changes - RailsCasts](http://railscasts.com/episodes/109-tracking-attribute-changes)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

Regards,  
Craig

–  
Craig D.  
Mutually Human Software

> **[Homepage | Mutually Human](https://www.mutuallyhuman.com/)**
>
> Technology Made for Humans by humans Data Analytics Data Analytics Data has become a critical part of business for most organizations. We work with you to ensure you have confidence in your data, can properly access it, and present it in a way that...

---

<div class="post-metadata">

**Author:** ![coolmenu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@coolmenu](https://www.ruby-forum.com/u/coolmenu)\
**Post date:** [May 28, 2009, 8:16pm UTC](https://www.ruby-forum.com/t/use-callbacks-to-determine-model-field-changes/168942/4 "2009-05-28T20:16:33Z")

</div>

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)…
