Rails“预览状态”使用 Cookie/会话
这似乎是一个常见问题,但我还没有找到非常“详细”的答案 - 我正在寻找允许用户在提交之前预览他们要提交的表单的最佳方法。
显然,将其存储在数据库中并不是最好的选择(这就是我现在正在做的事情),因为必须有一个过程来删除它,并且有很多场景。
详细信息
我不想向用户显示编辑操作,我想向用户显示显示操作,并且在屏幕的顶部和底部有一个 >发布按钮。
我的问题:
- 您将如何将表单中的信息存储到会话中(寻找一些控制器代码)
- 您如何知道您正在显示的show操作预览,而不是“真实”对象。 (或者您是否有单独的预览操作?)(在此处寻找一些控制器/视图代码)
- 一旦用户“完成”会话数据,您将如何删除它?
我认为存储在数据库中与存储在会话中具有相同的问题,即清理,我错了吗?最好的方法是什么?
This seems to be a common question, but I've yet to find a very 'detailed' answer - I'm looking for the best way to allow users to preview the form they are going to submit, before submitting it.
Obviously, storing this in the db isnt the best option (which is what I'm doing right now) because there has to be a process to remove it, and that has a lot of scenarios.
Details
I don't want to show the user the edit action, I want to show the user the show action, and at the top and bottom of the screen have a Publish button.
My questions:
- How would you go about storing the information from the form into a session (looking for some controller code)
- How would you know in the show action that you are displaying a preview, rather than a 'real' object. (or would you have a separate action for preview?) (looking for some controller/view code here)
- How would you remove the session data once the user is 'done' with it?
I think that storing in the database has the same issue with storing it in the session, the cleanup, am I wrong? What is the best way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将几天前创建的未发布记录视为已过时(用户必须了解该策略)。 Rake 任务可以通过 cron 每天执行一次或更频繁。此外,您还可以实现一些单独的 rake 任务来通知用户有关待处理的未发布记录,这些记录将很快被删除。草稿是一个好主意,如果您愿意或可以在较长时间内保持不变。
You can consider unpublished records created more than few days ago as obsolete (user must know about that policy). Rake task may be executed via cron once a day or more frequently. Also, you can implement some separate rake task to notify users about pending unpublished records, which will be removed soon. Drafts is a great idea and may be untouched if you like at all or for a longer time.