0

我在考虑是否有可能多个用户提交表单导致数据被覆盖。这是按时间顺序排列的动作流:

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中解决这个问题?

4

2 回答 2

1

如果他们要去同一个记录,除非你检查记录,否则你肯定会因为比赛而丢失数据。您需要检查记录以确保它在更新过程中没有更改。

如果您正在生成一条新记录,那么您很可能应该依赖数据库为其生成唯一记录和 id/key。

于 2013-09-12T00:37:38.067 回答
1

如果您使用的是 rails,您应该拥有csrf_meta_tags这会创建一个唯一的密钥,让您知道表单已提交并且每个用户都不同

于 2013-09-11T00:56:12.243 回答