一次只允许一个用户编辑内容 [英] Only one user allowed to edit content at a time

查看:182
本文介绍了一次只允许一个用户编辑内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果您要编辑 client-site.com/pages/5 ,则可以转到 admin-site.com/pages/5/edit 。我只想让一个管理员一次访问 admin-site.com/pages/5/edit

For instance, if you wanted to edit client-site.com/pages/5, you would go to admin-site.com/pages/5/edit. I want to only let one admin access admin-site.com/pages/5/edit at a time.

我计划在哪里做的是在数据库中创建editor_id和editing_rights_expiration_time列,并使用JavaScript /服务器端逻辑更新它们。是否有更好的方法实现此功能?

What I was planning on doing is creating the "editor_id" and "editing_rights_expiration_time" columns in the database, and updating them with JavaScript/server-side logic. Is there a better way of implementing this feature?

我使用Rails 3。

I'm using Rails 3.

推荐答案

您可能想查看一个乐观的锁定策略,所以让尽可能多的用户必须编辑页面。但是当用户尝试保存数据时,检查令牌是否已更改并拒绝编辑。例如:

You might want to look at an optimistic locking strategy, so let as many users as neccessary edit the page. But when the user tries to save the data check if the token has changed and reject the edit. For example:


  • 用户A开始编辑项目,并保存最后修改的时间戳记作为令牌

  • 用户B开始编辑该项目,并将最后修改的时间戳记作为令牌

  • 用户B保存其更改。上次修改的时间戳未更改,因此保存成功

  • 用户A保存更改。最后修改的时间戳已更改,因此拒绝其保存。

  • User A starts to edit the item and holds the last modified timestamp as the token
  • User B started to edit the item and also holds the last modified timestamp as the token
  • User B saves their changes. The last modified timestamp has not changed, so the save is successful
  • User A saves their changes. The last modified timestamp has changed, so their save is rejected. User could be offered the opportunity to resolve the conflict (if there is one).

看起来像Rails已经是@Andy了Waite(+1)提到。

Oh looks like Rails has this already as @Andy Waite (+1) has mentioned.

这篇关于一次只允许一个用户编辑内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆