轨道3:如何与QUOT; redirect_to时"在AJAX调用? [英] Rails 3: How to "redirect_to" in Ajax call?
本文介绍了轨道3:如何与QUOT; redirect_to时"在AJAX调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的 attempt_login
方法使用Ajax之后,登录表单提交调用。
The following attempt_login
method is called using Ajax after a login form is submitted.
class AccessController < ApplicationController
[...]
def attempt_login
authorized_user = User.authenticate(params[:username], params[:password])
if authorized_user
session[:user_id] = authorized_user.id
session[:username] = authorized_user.username
flash[:notice] = "Hello #{authorized_user.name}."
redirect_to(:controller => 'jobs', :action => 'index')
else
[...]
end
end
end
问题是, redirect_to时
不起作用。
你将如何解决这个问题?
How would you solve this ?
推荐答案
最后,我刚刚更换
redirect_to(:controller => 'jobs', :action => 'index')
这一点:
render :js => "window.location = '/jobs/index'"
和它工作得很好!
这篇关于轨道3:如何与QUOT; redirect_to时&QUOT;在AJAX调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文