Only one user allowed to edit content at a time

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

What I planned to do was create the "editor_id" and "edit_rights_expiration_time" columns in the database and update them using JavaScript / server logic. Is there a better way to implement this feature?

I am using Rails 3.

+2
source share
2 answers

I suspect that the best way to handle this is to use optimistic locking:

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

+2
source

You might want to take a look at an optimistic blocking strategy, so let as many users as possible edit the page. But when the user tries to save the data, check if the token has changed and rejected the change. For instance:

  • User A starts editing the item and holds the last modified timestamp as a token
  • User B started editing the item and also saved the last modified timestamp as a token
  • User B saves his changes. The last timestamp changed has not changed, so the save was successful.
  • User A saves his changes. The last timestamp changed has changed, so their storage is rejected. The user may be given the opportunity to resolve the conflict (if any).

It looks like Rails is already like @Andy Waite (+1).

+2
source

Source: https://habr.com/ru/post/1392225/


All Articles