Wes Gamble
2006-Nov-29 18:08 UTC
Fine tuning back button display when reviewing POST results
All, (This is more of a general Web app. issue, than any hard core Rails-specific thing.) I''ve recently made some modifications to my app. to better handle use of the back button in the browser (specifically IE 6/7 which forces a rePOST on hitting the back button). I went ahead and split my POST actions which were directly rendering templates into a POST action to modify state and then had each of these actions redirect to a separate GET action in order to display the modified state. This solution works fine for using "BACK" to review, since the requests in the history are all GETs. Things look seamless when you are moving backward between different URLs which are not displaying the same object data. However, I''m trying to figure out the best way to handle this when I have actions which POST and redirect back to the _same URL_. For example, I have a page which appends data to a list and then redisplays the updated list. So when you add a list item, you POST, redirect, and GET the same page as before, but now the display page shows the additional item. Now imagine browsing back through these pages. Because the list display page simply pulls the list object from session, doing a back from the page where there are 3 items will obviously not show me the page with 2 items since the display sees the current state of the model. That makes sense given how the page is generated. (A BIGGER QUESTION: Should I even be attempting to make concessions for the "page based" view of the application that the back button implies? I already have AJAX actions which change page display without regard for the back button, etc.) It would seem that one way to handle this specific case would be to: 1) Provide the # of items expected to the display action as a parameter 2) Make the display action smart enough to know how many items to display 3) Obviously, handle reposts of the form if they are done after backing up. In general, though, I believe that this means that when you are posting with the result as a redisplay of the same page, that you have to come up with a scheme to make those pages appear to have unique URLs (to satisfy the GET), and have a way to figure out what to display based on the unique URL. Is this correct? How have other people approached this issue, if at all? (This again raises an issue for me that in Rails that our views often have direct access to the model objects and that perhaps a separate set of "view models" which maintain view state would help in this type of situation). Thanks, Wes -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Long
2006-Nov-30 20:55 UTC
Re: Fine tuning back button display when reviewing POST results
Wes Gamble wrote:>...> However, I''m trying to figure out the best way to handle this when I > have actions which POST and redirect back to the _same URL_. For > example, I have a page which appends data to a list and then redisplays > the updated list. So when you add a list item, you POST, redirect, and > GET the same page as before, but now the display page shows the > additional item. > > Now imagine browsing back through these pages. Because the list display > page simply pulls the list object from session, doing a back from the > page where there are 3 items will obviously not show me the page with 2 > items since the display sees the current state of the model. That makes > sense given how the page is generated. > > (A BIGGER QUESTION: Should I even be attempting to make concessions for > the "page based" view of the application that the back button implies? > I already have AJAX actions which change page display without regard for > the back button, etc.) >I am not sure if I follow you fully but what would be the point in showing a stale-page when the list of items have already be updated? Given this sequence... /list - old list /add_item_post - add item to list and display updated /list /list - updated list At this point any BACK action to /list will always give you the updated list because the Browser was told to refresh its view of /list. If you must, perhaps attaching the number of items on the list to the URL may help. For example, /list - one item /add_item_post /list/2 /add_item_post /list/3 ... etc. HTH, Long www.edgesoft.ca/blog/read/2 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---