Forum: Ruby on Rails How to redirect to other action when it is called using ajax

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.
27490c77e0a39a397524a6c96648ccd6?d=identicon&s=25 stanly joe (stanly)
on 2007-04-19 12:23
Hi all,

I am using javascript to call an action with some parameters. In that
action i decide on the basis of parameters either to render some text on
that page or to re direct to some other page. But its seems that my
redirect_to method is not working from that action. Can anybody tell me
some way of redirecting to some other action     when that action is
called as a remote_function from javascript.

Thanks
8dad1ec4d769734583f45fbbee5cd009?d=identicon&s=25 Jeff Pritchard (Guest)
on 2007-04-19 17:19
Qasim Ali wrote:
> Hi all,
>
> I am using javascript to call an action with some parameters. In that
> action i decide on the basis of parameters either to render some text on
> that page or to re direct to some other page. But its seems that my
> redirect_to method is not working from that action. Can anybody tell me
> some way of redirecting to some other action     when that action is
> called as a remote_function from javascript.
>
> Thanks

It is unclear whether you are wanting to "leave ajax" at that point and
render a new rhtml page, or if you are wanting to "stay in ajax", and do
some sort of a "render :update" in that second action.  The answer
depends on which way you are wanting to go here.

In general, the "render :update redirect_to" will boot you out of the
ajax sequence back into a normal full page rendering.  To just re-route
your logic to another action, you can just call that action as a method
from the first action.  You have to take care to only do one rendering
regardless of which path your logic takes.

jp
This topic is locked and can not be replied to.