Ruby on rails 3 Rails 3和Desive-使用jQuery Mobile进行未经授权的重定向

Ruby on rails 3 Rails 3和Desive-使用jQuery Mobile进行未经授权的重定向,ruby-on-rails-3,jquery-mobile,devise,Ruby On Rails 3,Jquery Mobile,Devise,应用程序控制器: 我使用视图继承而不是其他格式(如:mobile) 显示控制器 class ShowsController < ApplicationController before_filter :authenticate_user! end class ShowsController

应用程序控制器:

我使用视图继承而不是其他格式(如
:mobile

显示控制器

class ShowsController < ApplicationController
  before_filter :authenticate_user!
end
class ShowsController
当我直接进入/显示我的浏览器时,我被正确地重定向到登录页面。 但是,当单击指向该页面的链接(ajax)时,我会得到一个
401未经授权的


我怎样才能解决这个问题?保持这种ajax加载页面会很酷。

将其放入application.js可能会帮助您:

// Set up a global AJAX error handler to handle the 401
// unauthorized responses. If a 401 status code comes back,
// the user is no longer logged-into the system and can not
// use it properly.
$.ajaxSetup({
    statusCode: {
        401: function() {

            // Redirect the to the login page.
            location.href = "/login";

        }
    }
});
资料来源:

// Set up a global AJAX error handler to handle the 401
// unauthorized responses. If a 401 status code comes back,
// the user is no longer logged-into the system and can not
// use it properly.
$.ajaxSetup({
    statusCode: {
        401: function() {

            // Redirect the to the login page.
            location.href = "/login";

        }
    }
});