ActiveRecord Locking
Optimistic Locking
Section titled “Optimistic Locking”user_one = User.find(1)user_two = User.find(1)
user_one.name = "John"user_one.save# Run at the same instanceuser_two.name = "Doe"user_two.save # Raises a ActiveRecord::StaleObjectErrorPessimistic Locking
Section titled “Pessimistic Locking”appointment = Appointment.find(5)appointment.lock!#no other users can read this appointment,#they have to wait until the lock is releasedappointment.save!#lock is released, other users can read this account