I’ve been trying to figure out how to use pessimistic locking. So far
I’ve found this:
row = table.find(:first, :lock=>true)
row.col = blah
I’m not that familiar with SQL or this activerecord layer so it’s a
little bit confusing. First of all, is that how you use it? Secondly,
this is what I’m trying to do:
render my form
save my form
When a user clicks on my link_to to go to “edit”, I want to lock 1 or
more rows (depending on a special # that identifies groups of rows in my
table) So if this number is 5, then I want to lock all rows with
“special”=5. I want it to be locked from editing, not from reading.
What is the exception that gets thrown if someone is already editing it?
So I can do something like:
flash[:notice] = “Try again later.”
Also, how do I unlock the rows when a user closes the browser, or
changes to a different page, or saves the form?
Thanks for the help!