Rails“预览状态”使用 Cookie/会话

发布于 2024-11-07 07:11:34 字数 534 浏览 0 评论 0原文

这似乎是一个常见问题,但我还没有找到非常“详细”的答案 - 我正在寻找允许用户在提交之前预览他们要提交的表单的最佳方法。

显然,将其存储在数据库中并不是最好的选择(这就是我现在正在做的事情),因为必须有一个过程来删除它,并且有很多场景。

详细信息
我不想向用户显示编辑操作,我想向用户显示显示操作,并且在屏幕的顶部和底部有一个 >发布按钮。

我的问题:

  1. 您将如何将表单中的信息存储到会话中(寻找一些控制器代码)
  2. 您如何知道您正在显示的show操作预览,而不是“真实”对象。 (或者您是否有单独的预览操作?)(在此处寻找一些控制器/视图代码)
  3. 一旦用户“完成”会话数据,您将如何删除它?

我认为存储在数据库中与存储在会话中具有相同的问题,即清理,我错了吗?最好的方法是什么?

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:

  1. How would you go about storing the information from the form into a session (looking for some controller code)
  2. 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)
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

桜花祭 2024-11-14 07:11:34

您可以将几天前创建的未发布记录视为已过时(用户必须了解该策略)。 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文