Skip to content

Instantly share code, notes, and snippets.

View andyzei's full-sized avatar

Andy Zeigler andyzei

View GitHub Profile
@andyzei
andyzei / selectively_optimistically_lockable.rb
Created May 28, 2015 21:58
SelectivelyOptimisticallyLockable for Rails 4+. Like the other gist, but doesn't override #update, which no longer exists. Also, it supports attribute lists in skip_optimistic_locking.
# Allows filtering out attributes that increment the ActiveRecord optimistic lock version, e.g. updated_at, or
# other attributes that will not cause a conflict issue.
module SelectivelyOptimisticallyLockable
extend ActiveSupport::Concern
private
def locking_enabled?
self.changed.any? {|att| !self.class.skips_optimistic_locking?(att) }