Can I do a redirect in an ajax request?

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?


you don’t have to use RJS, but RJS is probably the simplest way.

rjs ex:

page.redirect_to :controller => …, :action => …, …

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


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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs