2013-08-01 59 views
0

我正在Rails應用上開發一個ruby,我希望用戶在成功登錄設計後重定向到特定頁面。我在我的色器件會議控制器下面的代碼:用戶使用設備登錄後重定向到路徑時出錯

protected 
def after_sign_in_path_for(resource) 
if resource.role == "User" 
    redirect_to user_home_path 
else 
    redirect_to org_home_path 
end 
end 

我已經設置了控制器,顯示基於重定向的頁面。但是,登錄後出現以下錯誤:

AbstractController::DoubleRenderError in Webs::SessionsController#create 

Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that  neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return". 

我已經搜索過,但沒有運氣。請幫忙。

回答

5

after_sign_in_path_for應該只返回路徑,但不執行重定向,試着改變你的方法是這樣的:

def after_sign_in_path_for(resource) 
if resource.role == "User" 
    user_home_path 
else 
    org_home_path 
end 
end 
+0

當然,沒問題 – Benj