# Redirect\_to doesn't create history

**URL:** <https://www.ruby-forum.com/t/redirect-to-doesnt-create-history/195728>\
**Category:** Rails\
**Created:** [September 29, 2010, 6:17am UTC](https://www.ruby-forum.com/t/redirect-to-doesnt-create-history/195728 "2010-09-29T06:17:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/919ad9/32.png) [@jdc](https://www.ruby-forum.com/u/jdc)\
**Post date:** [September 29, 2010, 6:17am UTC](https://www.ruby-forum.com/t/redirect-to-doesnt-create-history/195728/1 "2010-09-29T06:17:53Z")

</div>

I have a wizard type flow where on each screen clicking the “continue”  
button posts data to the server, then I use redirect\_to to show the  
main wizard page (which dynamically shows partials based on the  
current state). The oddity I’m seeing - and maybe it’s just an HTTP  
thing - is that when these redirects happen, there is NO entry in the  
browser history - not even for the page that was redirected to. So,  
if this happens:

```
 GET /wizard (on "page 1" here)
 POST /wizard (form filled in on "page 1" is processed here,

```

model’s page parameter changed to “2”, then I do a redirect\_to  
wizard\_url)  
GET /wizard (on “page 2” here because the model had it’s page  
number changed)

What I see in history is the initial entry for wizard and that’s it.  
So if a user is on page 2 (or 3 or 4 or whatever) and hits their back  
button, they go back to whatever page was displayed before they first  
started the wizard.

Is there a special HTTP code I can set using the :status parameter to  
force it to put ALL of the GET requests in the history (even the ones  
initiated by redirect)?

Thanks for any help.

jc

---

<div class="post-metadata">

**Author:** ![jdc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/919ad9/32.png) [@jdc](https://www.ruby-forum.com/u/jdc)\
**Post date:** [September 29, 2010, 6:00pm UTC](https://www.ruby-forum.com/t/redirect-to-doesnt-create-history/195728/2 "2010-09-29T18:00:55Z")

</div>

On Sep 28, 2010, at 9:16 PM, jdc wrote:

> model’s page parameter changed to “2”, then I do a redirect\_to  
> force it to put ALL of the GET requests in the history (even the ones  
> initiated by redirect)?

There might be, but I haven’t heard of it. What your describing  
actually makes sense. A redirect implies the page is now elsewhere. So  
why save it in the history? That is…

GET /some-page (in history)  
GET /some-old-url (results in redirect to /some-new-url)  
GET /some-new-url (in history)

Why, normally would you want to see that second request in your browser  
history?

I don’t know how you have your app setup, but instead of redirecting,  
what about sending back an almost empty page containing just enough  
javascript or meta-refresh to take you to the next page.

-philip

---

<div class="post-metadata">

**Author:** ![jdc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/919ad9/32.png) [@jdc](https://www.ruby-forum.com/u/jdc)\
**Post date:** [October 1, 2010, 5:52pm UTC](https://www.ruby-forum.com/t/redirect-to-doesnt-create-history/195728/3 "2010-10-01T17:52:33Z")

</div>

Thanks for the reply. You’re correct - and in your example I’d expect  
to see the following in history:

- /some-page
- /some-new-url

That’s not exactly what I was describing though. In my case, think of  
it as /some-old-url actually redirecting to /some-page instead of /  
some-new-url. Since the browser sees a redirect to /some-page - which  
is the same url it’s already on - it seems to say “ok, I didn’t go  
anywhere” and not change the history at all. So in the history I only  
have:

- /some-page

From a browser standpoint, this makes since because it doesn’t know  
that /some-page is dynamically generated based on state saved in a  
DB.

This question really arose from me trying to keep a single URL for  
every page in the wizard and just display whatever step the user was  
actually on. After thinking about the problem for a bit, I decided  
that each wizard step is actually a different page and needs it’s own  
URL - it didn’t really make sense to do what I was doing. This solved  
the problem completely for me since with different URLs the history is  
working the way I’d expect - and code got a lot cleaner too!
