Skip to content

Instantly share code, notes, and snippets.

@semind
Forked from zflat/note_for_locking
Created June 23, 2012 09:15
Show Gist options
  • Save semind/2977662 to your computer and use it in GitHub Desktop.
Save semind/2977662 to your computer and use it in GitHub Desktop.
rails with_lock
see http://guides.rubyonrails.org/3_2_release_notes.html
This makes it possible to write the following:
class Order < ActiveRecord::Base
def cancel!
transaction do
lock!
# ... cancelling logic
end
end
end
as:
class Order < ActiveRecord::Base
def cancel!
with_lock do
# ... cancelling logic
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment