Forum: Ruby on Rails Optimistic Locking and How to Handle?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
5565e460a42fbe5669b458b2753f8d34?d=identicon&s=25 Michael (Guest)
on 2007-04-18 22:56

I need to use the magic column "lock_version" to prevent users from
updating a record simultaneously.  I've got it working without a

Has anyone implemented a nice way to handle the conflict resolution.  I
don't want to just tell the user - Sorry, already been updated, try
again.  Instead, I would like to present a list of fields that are
conflicted and allow that user who got the error to determine how they
want to handle the conflict and then save the record.

It seems the way to do something like this would be to query the record
by id when the StaleObjectError exception is caught.  Then, compare the
params submitted with the freshly queried record and come up with a list
of values that are different.  Take this list, send it back to the user
and let them decide what to do.

Instead of writing this from scratch my guess is someone on this list
has already done something similar.

Any pointers?


4a9e00598cbbb475cc9e117360e07fcf?d=identicon&s=25 Christoph Olszowka (Guest)
on 2007-06-12 13:25
(Received via mailing list)

it's been some time since your post, but I'll respond to it anyway
maybe you're still looking for a solution.

I'd suggest you to use Riff. It will let you compare two AR objects
with each other. Before you apply the form data to your object,
you could clone it to a @dbrecord-var and afterward compare
both objects with Riff. You can find more on riff here:

This topic is locked and can not be replied to.