开发者

Handle version conflict when multiple concurrent editor on the same model rails

how to Handle version conflict when multiple concurrent editor on the same model rails? for example user A click edit on the post controller开发者_开发问答 and start editing the content user B click edit on the post controller and start editing the title user B is done and click save user A is done and click save and override the modifications done by User B

is there to prevent that ? i'm thinking of using the updated_at field to check that the version edited is the last one. any plugin or gem to do that ??


I'm not aware of any plugins or gems that take care of this directly (i.e. by handling everything from the model to the views), and have searched briefly on gemcutter.org and agilewebdevelopment.com for plugins to no avail.

One up and coming program/package that manages this very well is Google Wave.

But if that's not an option (as it almost certainly will not be), here's a quick and very simple idea that might get you there:

  1. Add a field to the 'edit' view called "requested_at"

  2. When you receive the 'update' for an edit, check whether the "requested_at" form field value is less than the stored object's "updated_at" value.

  3. If it is, send a response to the browser warning the user of the possible conflict. You could even display a difference between the user's submitted data and the current state of the stored object. For this 'diff' display I recommend the diff-lcs library available at gemcutter: http://gemcutter.org/gems/diff-lcs

  4. After the user views and revises his subimssion, rinse and repeat (or give them the option to override any existing changes even if someone else has edited the text).

An answer below mentioned the use of versioning for your active_record models, and for that you could try ActsAsAudited (at least that's my favorite)...but I'm not sure that's the problem you were describing.


What you are looking for is a revision control or version control system for ActiveRecord. The Ruby Toolbox indexes several of them. laserlemon's vestal_versions looks like it would get the job done. I'm not sure if it handles version-conflicts out of the box, but could be done with a fork and some editing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜