2013-08-01 29 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