Rails 3 app doesn't redirect after AJAX form submission -


i have authlogic login form :remote => true little inline validation rjs template if user/password isn't valid. works fine, when credentials are valid, doesn't redirect elsewhere.

here's controller responds form input:

class usersessionscontroller < applicationcontroller   respond_to :html, :js    before_filter :require_no_user, :only => [:new, :create]   before_filter :require_user, :only => :destroy    def new     @user_session = usersession.new   end    def create     @user_session = usersession.new(params[:user_session])      respond_to |format|       if @user_session.save              flash[:notice] = "login successful!"         format.html { redirect_to account_url }       else         format.js       end     end   end    def destroy     current_user_session.destroy     flash[:notice] = "logout successful!"     redirect_to root_path   end  end 

the format.js part works if user/password (format.html), nothing happens. however, if development.log, is requesting account_url page. it's not redirecting in browser. think it's returning account page via ajax , want normal redirect.

the html form this:

<%= simple_form_for( :user_session, @user_session,  :url => { :controller => 'user_sessions', :action => "create" }, :html => { :id => 'login-dropdown' }, :remote => true) |f| %> 

i found way fix it. per http://www.ruby-forum.com/topic/168406#945053, added following application controller:

def redirect_to(options = {}, response_status = {})   if request.xhr?     render(:update) {|page| page.redirect_to(options)}   else     super(options, response_status)   end end 

this prevents redirect response being delivered via xhr. if there's more "correct" way of doing in controller, i'd hear it, though.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -