开发者

Rails 'Preview State' Using Cookies/Session

开发者 https://www.devze.com 2023-03-06 12:09 出处:网络
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.

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, ra开发者_运维技巧ther 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?


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.

0

精彩评论

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

关注公众号