Rails 3:如何“redirect_to"在 Ajax 调用中? [英] Rails 3: How to "redirect_to" in Ajax call?
本文介绍了Rails 3:如何“redirect_to"在 Ajax 调用中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在提交登录表单后,使用 Ajax 调用以下 attempt_login
方法.
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
不起作用.
The problem is that redirect_to
doesn't work.
你会如何解决这个问题?
How would you solve this ?
推荐答案
最后我才换了
redirect_to(:controller => 'jobs', :action => 'index')
这样:
render :js => "window.location = '/jobs/index'"
而且效果很好!
这篇关于Rails 3:如何“redirect_to"在 Ajax 调用中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文