Optimistic Locking and How to Handle?

Hello,

I need to use the magic column “lock_version” to prevent users from
updating a record simultaneously. I’ve got it working without a
problem.

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?

Thanks,

Michael

Hi,

it’s been some time since your post, but I’ll respond to it anyway
because
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:
http://wiki.rubyonrails.org/rails/pages/Riff+Plugin

Greetings,
Christoph