Forum: Ruby on Rails Can I do a redirect in an ajax request?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Pat M. (Guest)
on 2006-04-02 02:51
(Received via mailing list)
I've got a form on my page, and when the user submits it, sometimes
I'd like to update an element on my page, and sometimes I'd like to
redirect the browser to another url entirely.  However if I do
redirect_to, it just updates the element with the results of the
redirect.  Is it possible to do what I want, or will I need to use RJS
to do this?

Chris H. (Guest)
on 2006-04-02 03:03
(Received via mailing list)
you don't have to use RJS, but RJS is probably the simplest way.

rjs ex:

page.redirect_to :controller => ..., :action => ..., ...
Pat M. (Guest)
on 2006-04-02 03:06
(Received via mailing list)
Yeah I did some googling, and found that I could put this in the

render :update do |page|
  page.redirect_to home_url

However when I do that, the text "window.location.ref=...." shows up
on the page.  I don't want the user to see that...maybe I can have it
show a custom message when it performs the action instead or

Pat M. (Guest)
on 2006-04-02 03:18
(Received via mailing list)
Okay once I took the update out of the form_remote_tag call, and just
used page.replace_html inside my controller, everything works nicely
and doesn't show the JS in the page anymore.  Thanks Chris!

This topic is locked and can not be replied to.