Forum: Ruby on Rails ajax 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.
Sebastien H. (Guest)
on 2006-03-24 12:48
(Received via mailing list)

Is there a simple way to redirect towards another page (controller,
when using form_remote_tag ?

I used it tipically to check fields of a account login form. I'd like
if the user
exists, he's redirected towards another page, otherwise I display some
error div's.

Any ideas ?
Thanks a lot.
Emin H. (Guest)
on 2006-03-24 12:59
(Received via mailing list)
You should put a callback in your tag like:

:complete => "redirect(request)"

and then add redirect() javascript function that will check
request.ResponseText and do a client-side redirect if it meets
required criteria

more on ajax callbacks here:
Chris H. (Guest)
on 2006-03-24 17:51
(Received via mailing list)
if you are using rjs (plugin for 1.0 or built-in for 1.1), you can use



<%= form_remote_tag :url => { :action => :login } %>
<%= end_form_tag %>
<div id="login_msg"></div>


class AccountController < ApplicationController
  def login
    # the prototype library sends a "X-Requested-With" header containing
    # so we can tell if it's an AJAX call or not
    if request.xhr?
      # authenticate the user
      @authenticated = User.authenticate(@params[:login],
      # go on to render the login.rjs template
      # not an ajax call, so we display the login form partial instead
      render :partial => "login_form", :layout => false


if @authenticated
  # user has authenticated so send them to where they need to go
  # auth failed so update the message div to let them know
  page.replace_html("login_msg", "Bad username or password")
This topic is locked and can not be replied to.