Forum: Ruby on Rails detecting changed data - retry

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-06-08 17:28
(Received via mailing list)
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
B780ee0ee1480454a85df58536702f63?d=identicon&s=25 Alder Green (Guest)
on 2006-06-08 18:06
(Received via mailing list)
On 6/8/06, Craig White <craigwhite@azapple.com> wrote:
> value is put into the current hash...but that value doesn't change if I
> 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.
This topic is locked and can not be replied to.