简体   繁体   中英

Only one user allowed to edit content at a time

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.

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?

I'm using Rails 3.

I suspect a better way to handle this would be to use optimistic locking:

http://railscasts.com/episodes/59-optimistic-locking

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:

  • 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).

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM