how to forbidden page cache on rails -
i'm design shopping cart,there 2 web page,
first checkout page,and second order_success page
if user use go button on webbrowser go checkout page after user have go order_success page.
so want find way forbidden let use go back,
is there way on rails archieve this?
"i know user use go button,if there cache in client, user still see & re-submit, not expect" [was meaning?]
if want prevent user resubmit same request, may add hidden field (just random) , store in session after 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 use cart id in request, may use status of cart model:
@cart = cart.find(params[:id]) render_some_notice , return if @cart.done? .... @cart.done = true @cart.save
personally not create checkout , order_success pages. create single page - cart status, , depending on model status display different content.
if action may executed once (like closing cart or finalizing transaction) there no problem: render_something , return if @cart.already_closed?
on pages, multiple submits possible, not welcome (like adding product cart - user can add 2 identical products) may 2 things:
1) use mentioned token, detect when user pressed f5, , ask him whether action should done twice, or
2) accept requests, provide user methods 'rollback' actions (allow him delete products cart), , ensure cart content verified before final acceptance.
Comments
Post a Comment