2010-03-23 25 views
2

我有一個程序,其中的寶石,臉譜,調用重定向,並在同一行動中,我最終通過redirect_back_or_default調用重定向。我的問題是:Rails,處理多個重定向

  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 

或者你可以測試(在我看來這是沒有好的做法)for response_bod y類似於ActionController所做的:

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

    redirect_to '/tester/index' unless response_body 
    end  
end