开发者

Creating an action based on countdown

开发者 https://www.devze.com 2023-03-10 01:55 出处:网络
imagine that you had a t开发者_Go百科ask that finished in, say 10 seconds. Now, after the 10 seconds pass, the user has to be redirected back to a specific page with the results of that task. This red

imagine that you had a t开发者_Go百科ask that finished in, say 10 seconds. Now, after the 10 seconds pass, the user has to be redirected back to a specific page with the results of that task. This redirection has to happen, even if the user is viewing another page.

As you can imagine, there is a start and end time in the model that shows when the event started and when it ends. My question is, how would you design that, also taking a close look into security ?

I do it this way currently : I have a global before_filter which has a method that constantly checks on whether the event has finished and sets a session variable to 1 if so. If it's indeed finished, it redirects to a GET action that is only reachable if the session variable is set to 1.

This latter action is doing the things i need and renders information back to the user. Do you think i'm handling it correctly, or you would do things differently ?


It sounds like your design is ok.

Depending on your requirements, you might be able to skip the redirect by rendering the view right away and then setting the correct url using javascript. Here is information on how to do that: How does GitHub change the URL but not the reload?.

0

精彩评论

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