[Rails] Re: When to use optimistic locking?

Jason Tuttle
2006-05-09T18:03:06Z

Peter De Berdt wrote:
>> What if I want to guard against 2 people simultaneously updating
>> the same customer record? How would I go about doing this? I
can''t
>> find any examples online, and I''m a bit lost.
>
> Well, first of all, you need a lock_version column in your model
> (table) (or override it with the "set_locking_column" method). If
a
> record has been changed by someone else, Rails will throw a
> StaleObjectError, you need to trap this error and handle it
> appropriately (present the user with a dialog confirming to update
> the record anyway or cancel it). It''s up to you to find a way to
> handle the error.
>
> Best regards
>
> Peter De Berdt

Thanks Peter, but in the scaffold generated CRUD code, the model state
is lost between the "edit" and "update" calls. -- the
StaleObjectError
will never be thrown.

: )

Jason