Skip to content

Instantly share code, notes, and snippets.

@zflat
Created April 3, 2012 15:04
Show Gist options
  • Save zflat/2292754 to your computer and use it in GitHub Desktop.
Save zflat/2292754 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