what's a RESTful way to save draft posts?

牧云@^-^@ 提交于 2019-12-02 21:21:59

Auto-save:

application.js

$(document).ready(function() {
  setInterval(function() {
    $('form[data-remote]').submit();
  }, 1000*60); // 1000ms * 60s = 1m
});

You'll then need to have an update.js.erb to handle the messages ("Saved", for example).

For drafts, I would make a separate model, PostDraft. The auto-save will be saving the PostDraft object, and then once they click "Publish" or whatever, it will create a new Post and delete the PostDraft. This method will also allow the user to have titles longer than the limit, just by not putting that validation on the PostDraft model. This would be a lot more difficult if you did it all from within the Post model with a "draft" boolean.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!