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:
- Provide the # of items expected to the display action as a parameter
- Make the display action smart enough to know how many items to
display - 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