2010-03-23 3 views
2

이 나는 ​​보석, facebooker는, 리디렉션을 호출하고 동일한 작업에서 나는 redirect_back_or_default를 통해 리디렉션을 callling 결국 프로그램을 리디렉션합니다. 내 질문 :레일 여러 취급

  1. 여러 리디렉션 오류를 잡을 수있는 방법이 있습니까? 시작/구조 블록은 그렇게하지 않는 것 같습니다.
  2. 아니면 리디렉션이 이미 호출 되었기 때문에 다음 호출을 호출하지 않는지 확인하는 방법이 있습니까?

이 시점에서 나는 facebooker gem을 수정하고 싶지 않으므로 이것을 처리하는 가장 좋은 방법은 무엇이라고 생각하십니까?

모두 감사합니다, 저스틴

답변

2

ActionController#redirect_to의 소스에보기 아웃하는 데 도움이 :

raise AbstractController::DoubleRenderError if response_body 

당신은 다음과 같이 예외를 구출 (그냥 로그 라인 생략) 수 :

class TesterController < ApplicationController 
    #I am redirecting ever to index.html 
    def index 
    redirect_to '/index.html' 

    redirect_to '/tester/index' 
    rescue AbstractController::DoubleRenderError 
    Rails.logger.info "I redirected two times at least but the user doesn't know" 
    end 
end 

또는 내 의견으로는 우수 사례 ()입니다. response_bod 유사 설명 y ActionController는 무엇을 :

class TesterController < ApplicationController 
    def index 
    redirect_to '/index.html' 

    redirect_to '/tester/index' unless response_body 
    end  
end