2012-07-27 3 views
3

응용 프로그램 컨트롤러를 무단으로 리디렉션 :레일 고안 3 - jQuery를 모바일

내가 대신 다른 형식의 뷰 상속을 사용 (같은 :mobile)

before_filter :subdomain_view_path 

def subdomain_view_path 
    prepend_view_path "app/views/mobile" if request.server_name.include?("mobile") || request.user_agent =~ /Mobile|iPad/ 
end 

쇼 컨트롤러

class ShowsController < ApplicationController 
    before_filter :authenticate_user! 
end 

때 내 브라우저에서 바로/show로 이동하면 로그인 페이지로 올바르게 리디렉션됩니다. 그러나 해당 페이지로 링크 (아약스)를 클릭하면 401 Unauthorized가 표시됩니다.

어떻게 해결할 수 있습니까? 페이지의 아약스로드를 유지하는 것이 좋습니다.

답변

0

당신 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"; 

     } 
    } 
}); 

출처 : http://rubythings.blogspot.de/2011/10/ajax-redirects-with-devise.html