Ajax substitute for "redirect_to"


#1

######## Short version:

I need an ajax version of “redirect_to” that either
triggers the browser to do a new XHR (XML-HTTP-Request)
or
triggers rails to behave as if a clean new XHR had come in.

######## Long version:

I have an existing non-ajax rails website. I want to change it in the
way
that I can toggle a switch and the site uses link_to_remote instead of
link_to. This job is done, it works fine. The solution uses .rjs
templates
which make the changes by calling “page.replace_html” for the dynamic
parts
of the page. So far so good.

Now I need an ajax-version for all the “redirect_to”'s in the existing
code.
I see two possible solutions here:

  1. Tell the browser to do a new XHR

The helper “link_to_remote” produces someting like:

dummy

I need an rjs template that, if interpreted by rails and received by the
browser, tells the browser to behave as if the user klicked on the above
“link_to_remote”.

Again with other words: what does an .rjs template look like that tells
the
browser to do an XHR immediately?

  1. Tell rails to forget everything it did so far and behave as if there
    was
    a new request x coming in

Is it possible and if how to tell rails: Reset everything you did for
the
current browser request and then handle the following action call as if
it
was produced by a clean new browser request (including everything,
especially the rendering)?

######## Call for help

I followed both ways for hours but didn’t succeed. My knowledge of rails
internals isn’t experienced enough by now. Any help is very much
appreciated.


#2

In your controller -

render :update do |page|
page.redirect_to ‘new_url’
end

This is equivalent to window.location.href = ‘new_url’

Heiner Bunjes wrote:

######## Short version:

I need an ajax version of “redirect_to” that either
triggers the browser to do a new XHR (XML-HTTP-Request)
or
triggers rails to behave as if a clean new XHR had come in.


#3

Chet Sanders wrote:

In your controller -

render :update do |page|
page.redirect_to ‘new_url’
end

This is equivalent to window.location.href = ‘new_url’

Thanks, but this does not at all help me. Maybe the subject was
misleading. I don’t want the browser to do a normal http-request, I want
it to do an XML-HTTP-Request.


#4

This discussion is going on at:

http://railsforum.com/viewtopic.php?pid=17413#p17413

So if you are interested, have a look there!

Any help very much appreciated.