Forum: Ruby on Rails ajax substitute for "redirect_to"

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F8c4ae129ec0bd6817b7ee8e99f9522b?d=identicon&s=25 Heiner Bunjes (wotanabi)
on 2007-03-21 14:03
######## 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:

<a onclick="new Ajax.Request('/dummy/test1?mode=update',
{asynchronous:true, evalScripts:true, method:'get'});
return false;" href="#">dummy</a>

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?

####
2. 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.
C8ef22bb0256e9e31371530dfa86ec2b?d=identicon&s=25 Chet Sanders (chet_sanders)
on 2007-03-21 15:18
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.
>
>
F8c4ae129ec0bd6817b7ee8e99f9522b?d=identicon&s=25 Heiner Bunjes (wotanabi)
on 2007-03-21 15:45
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.
F8c4ae129ec0bd6817b7ee8e99f9522b?d=identicon&s=25 Heiner Bunjes (wotanabi)
on 2007-03-23 20:03
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.
This topic is locked and can not be replied to.