1

我正在开发一个 ruby​​ on rails 应用程序,我希望用户在使用 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".

我已经搜索过,但没有运气。请帮忙。

4

1 回答 1

9

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
于 2013-08-01T13:28:32.423 回答