Forum: Ruby on Rails question about ajax/rjs and redirection

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.
Chris H. (Guest)
on 2006-03-16 14:41
(Received via mailing list)
i don't even know if this is possible, so I'll just ask.

say I have a remote form.  the form data gets submitted to the backend
AJAX.  if there is a validation error in the form, i handle that on the
side.  however, if the form validates, I'd like to redirect the browser
to a
different page.  Will a redirect_to work with an AJAX call or do I have
handle that a special way?


class AjaxController < ApplicationController::Base

  def do_something
    #validate the form data
    redirect_to :controller => "xyz", :action => "abc" and return if
    # otherwise, render the rjs template
Emin H. (Guest)
on 2006-03-16 15:48
(Received via mailing list)
you need to check a result and if positive do a client-side redirect
Chris H. (Guest)
on 2006-03-24 15:08
(Received via mailing list)
you can do

def do_something
  #validate form data
  render :update { |page|  page.redirect_to("/controller/action") } if
  #otherwise render rjs template
This topic is locked and can not be replied to.