# Optimistic locking and update\_attributes: not working?

**URL:** <https://www.ruby-forum.com/t/optimistic-locking-and-update-attributes-not-working/90087>\
**Category:** Rails\
**Created:** [March 25, 2007, 11:16pm UTC](https://www.ruby-forum.com/t/optimistic-locking-and-update-attributes-not-working/90087 "2007-03-25T23:16:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![blair](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c37758/32.png) [@blair](https://www.ruby-forum.com/u/blair)\
**Post date:** [March 25, 2007, 11:16pm UTC](https://www.ruby-forum.com/t/optimistic-locking-and-update-attributes-not-working/90087/1 "2007-03-25T23:16:40Z")

</div>

Hi all,

I’ve searched the forumns, but I can’t seem to find an answer to this  
one. I’m having trouble getting optimistic locking (OL) to work in my  
app, even though all of the pieces are there:

- table has lock\_version column, with default of 0 (zero)
- lock\_version column is being incremented by the first update (but the  
second doesn’t catch it)
- I’m trapping for ActiveRecord::StaleObjectError, but it is never  
thrown

But nothing seems to work.

Note that currently, I’m still in development mode and using the  
scaffolding code that relies on update\_attributes, but I haven’t found  
any documentation that states whether OL works/does not work in  
development mode or with update\_attributes.

Anyone have an answer for this, and/or code they are willing to share?

Many thanks,

Eric

---

<div class="post-metadata">

**Author:** ![blair](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c37758/32.png) [@blair](https://www.ruby-forum.com/u/blair)\
**Post date:** [August 9, 2007, 6:25pm UTC](https://www.ruby-forum.com/t/optimistic-locking-and-update-attributes-not-working/90087/2 "2007-08-09T18:25:10Z")

</div>

I’m having the same problem. Does anyone have any ideas? I’ve Googled,  
looked at documentation and I’m coming up empty…
