开发者

how to forbidden page cache on rails

i'm design a shopping cart,there are t开发者_开发百科wo web page,

first is checkout page,and the second is order_success page

if user use the go back button on webbrowser then it will go back to checkout page after user have go to order_success page.

so i want to find some way to forbidden let use go back,

is there some way on rails to archieve this?


"i know this but user will use the go back button,if there some cache in client, user still could see something & re-submit, this is not what I expect" [was that the meaning?]

If you want to prevent the user resubmit the same request, you may add a hidden field (just something random) and store it in a session after the request has been processed:

if params[:token] == session[:used_token]
  render_already_processed_notice
  return
end
if @cart.save
  session[:used_token] = params[:token]
....

If you use a cart ID in a request, then you just may use the status of the Cart model:

@cart = Cart.find(params[:id])
render_some_notice and return if @cart.done?
....
@cart.done = true
@cart.save

Personally I would not create a checkout and order_success pages. I would just create a single page - cart status, and depending on the model status I would just display different content.

If some action may be executed only once (like closing the cart or finalizing the transaction) there is no problem: render_something and return if @cart.already_closed?

On pages, where multiple submits are possible, but not always welcome (like adding a product to the cart - the user can add two identical products) you may do two things:

1) Use the mentioned token, which will detect when the user just pressed F5, and ask him whether the action really should be done twice, or

2) Just accept the requests, but always provide the user with methods to 'rollback' the actions (allow him to delete products from the cart), and ensure that the cart content will be verified before final acceptance.


  1. clear shopping cart
  2. redirect user to new action

After a purchase is successful you should clear the shopping cart and then redirect the user to a new action.

In your order_controller.rb

 def create
     @shopping_cart = nil
     redirect_to some_path
 end 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜