Rails 3 - Potential Race Condition?
问题 I have a really simple Rails 3 application where users can reserve one of a finite number of homogeneous items for a particular day. I'm trying to avoid a race condition where two people reserve the last item available on a particular day. The model (simplified) is as follows: class Reservation < ActiveRecord::Base belongs_to :user attr_accessible :date MAX_THINGS_AVAILABLE = 20 validate :check_things_available def check_things_available unless things_available? errors[:base] << "No things