用户使用设计登录后重定向到路径时出错

时间:2013-08-01 13:24:15

标签: ruby-on-rails devise

我正在开发rails应用程序上的ruby,我希望用户在使用devise成功登录后重定向到特定页面。我的设计会话控制器中有以下代码:

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".

我搜索过,但没有运气。请帮助。

1 个答案:

答案 0 :(得分:7)

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