# Auto update model

**URL:** <https://www.ruby-forum.com/t/auto-update-model/163023>\
**Category:** Rails\
**Created:** [March 16, 2009, 7:11pm UTC](https://www.ruby-forum.com/t/auto-update-model/163023 "2009-03-16T19:11:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [March 16, 2009, 7:11pm UTC](https://www.ruby-forum.com/t/auto-update-model/163023/1 "2009-03-16T19:11:37Z")

</div>

I have a model: user (id, username, password, … key), where “key” is  
sha1 hach of username + password.  
How can I update key every time when user update own information?

---

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [March 16, 2009, 7:25pm UTC](https://www.ruby-forum.com/t/auto-update-model/163023/2 "2009-03-16T19:25:08Z")

</div>

> I have a model: user (id, username, password, … key), where “key” is  
> sha1 hach of username + password.  
> How can I update key every time when user update own information?

Look into the “before\_save” callback, check to see if values have  
changed and if so set a new key.

-philip
