我在想,是否有可能多個用戶提交表單導致數據被覆蓋。 這是行動的時間順序流:Rails表單提交競賽條件?
1. User 1 clicks on Edit, rails render the page that has <form> and has value {A: 1, B: 2}
2. User 2 clicks on Edit, rails render another page that has <form> and has value {A: 1, B: 2}
3. User 1 updates value A to 5 and clicks on Submit, passing to server {A: 5, B: 2}
4. Server updates to database to {A: 5, B: 2}
5. User 2 updates value B to 10 and clicks on Submit, passing to server {A: 1, B: 10}
6. Server updates to database to {A: 1, B: 10}
由於用戶2瀏覽器有舊數據。當B點擊提交時,字段A被過濾爲1.用戶1的更新被覆蓋。
如何在rails中解決這個問題?