2011-08-08 28 views
0

從幾個位置我檢查服務條款是否已被接受。如果沒有,用戶應該被重定向到服務條款,然後返回到他們要去的地方。我不想通過解釋爲什麼我不使用'request.referer'來複雜化這個問題。redirect_to存儲在變量中的路徑未完成

我正在做的是使用session [:return_to] =返回的路徑。所以......在一個控制器我有:

def index 
    if current_user.tos_at.nil? 
    session[:return_to] = 'answers path' 
    redirect_to terms_of_service_controller_index_path 
    end 
    ... 
end 

然後顯示後的服務條款和接受的過程中用戶點擊指向:

高清accept_terms_of_service current_user.update_attributes(:tos_at => Time.now) redirect_to的會話[:的return_to] 端

然後我得到:

"You are being redirected." 

之後,在瀏覽器中打印,沒有任何反應。如果我將重定向更改爲:

redirect_to answers_path 

它重定向到正確的路徑。

感謝您的幫助。

回答

1

分配會話[:的return_to]正確:

session[:return_to] = answers_path 

answers_path是一個幫助,所以當你指定會話[:的return_to]像「answers_path」的值,它試圖重定向到其位於頁面在'answers_path'中。

做到這一點,第二個方法是不修改會話[:的return_to]分配,但

redirect_to send(session[:return_to]) 
+0

由於更換

redirect_to session[:return_to] 

,@Hck。太棒了。 – Jay