# Detecting changed data - retry

**URL:** <https://www.ruby-forum.com/t/detecting-changed-data-retry/62835>\
**Category:** Rails\
**Created:** [June 8, 2006, 5:28pm UTC](https://www.ruby-forum.com/t/detecting-changed-data-retry/62835 "2006-06-08T17:28:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [June 8, 2006, 5:28pm UTC](https://www.ruby-forum.com/t/detecting-changed-data-retry/62835/1 "2006-06-08T17:28:21Z")

</div>

I didn’t get much traction on this so I am trying again…

I am working on an application where there are many different screens to  
access the data in a particular record/row. I have links to each data  
entry screen at the top. Is there a way to detect whether the current  
hash has been changed from the stored record so I can prompt the user if  
they attempt to change screens without having saved their changes to the  
data?

I have added a field to my db called ‘updated\_at’ and the db in the  
value is put into the current hash…but that value doesn’t change if I  
change another value on an input screen - unless I save, which of course  
is what I am trying to detect…the need to save.

Is there a method for doing this?

Craig

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [June 8, 2006, 6:06pm UTC](https://www.ruby-forum.com/t/detecting-changed-data-retry/62835/2 "2006-06-08T18:06:01Z")

</div>

On 6/8/06, Craig W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> value is put into the current hash…but that value doesn’t change if I  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

If I understand your question, it seems the most optimized way (unless  
your’e keeping track of a huge amount of data) is to store the current  
values in JavaScript on the browser end. Then you can have a simple JS  
callback to check if the user changed anything. I did this in other  
frameworks before I switched to Rails, so I don’t know if there’s any  
help in Rails for doing that (but I guess there is).

The other option is, instead of sending all the db values to the  
browiser in the beginning, to “call home” and check the current form  
values against the database, via an AJAX call. It would obviously be  
less fast than the former way, but might be seen as more elegant and  
DRY, especially if there’s a lot of information in these forms, and  
the user is likely to just change a bit of it.
