简体   繁体   English

登录后重定向时出现“ user_path”错误

[英]devise 'user_path' error when redirecting after log-in

I used this code block in devise,from https://coderwall.com/p/djgkag , to return the users where they came from after a successful login: 我从https://coderwall.com/p/djgkag设计使用了以下代码块,以在成功登录后返回用户的来源:

def after_sign_in_path_for(resource_or_scope)
  session.fetch 'user_return_to', user_path
end

But i get an error that says: 但我收到一条错误消息:

NameError in SessionsController#create undefined local variable or method `user_path' for # SessionsController中的NameError#为#创建未定义的局部变量或方法`user_path'

How will I define user_path? 我将如何定义user_path? or how will i replace it? 或者我将如何替换它? I've run rake routes and its not there indeed. 我已经运行过耙路,但确实没有。

You could try and do the following: 您可以尝试执行以下操作:

def after_update_path_for(resource)
  session[:return_to] ||= request.referer
end

With this you can then call this in your controller by doing redirect_to session[:return_to] . 这样,您就可以通过执行redirect_to session[:return_to]在您的控制器中调用它。 If that does not work, take a look at How To: Redirect back to current page after sign in, sign out, sign up, update . 如果这样做不起作用,请查看如何:登录,注销,注册,更新后重定向到当前页面 Which should detail what your after. 哪个应该详细说明您的工作。 But try the way I suggested first. 但是请尝试我建议的方式。

Maybe you should redirect to edit_user_registration_path. 也许您应该重定向到edit_user_registration_path。

Devise does not provide any profil page by default. 默认情况下,Devise不提供任何配置文件页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM