[英]Using Devise with Ruby on Rails, how can I send the user to sign_in path if they use an invalid auth_token?
When I send a user to /dashboard?auth_token=XXX
, and the auth_token
is incorrect, the user gets taken to the root_path
. 当我将用户发送到
/dashboard?auth_token=XXX
,并且auth_token
不正确时,用户将被带到root_path
。
In this situation, I want the user to be taken to the sign_in
path, and then be taken to /dashboard
after they sign in. How can I do this? 在这种情况下,我希望用户被带到
sign_in
路径,然后在他们登录后被带到/dashboard
。我该怎么做?
The default in Devise is to redirect to "new_#{scope}_session_path" route if one is available. Devise中的默认值是重定向到“new _#{scope} _session_path”路由(如果有)。 As seen here:
如下所示:
https://github.com/plataformatec/devise/blob/master/lib/devise/failure_app.rb#L89 https://github.com/plataformatec/devise/blob/master/lib/devise/failure_app.rb#L89
So, assuming you are using the user scope, be sure you have a new_user_session_path
defined by your router. 因此,假设您使用的是用户范围,请确保路由器已定义
new_user_session_path
。
About redirecting back to the original page, try out this wiki page: 关于重定向回原始页面,请试用此Wiki页面:
https://github.com/plataformatec/devise/wiki/How-To:-Redirect-back-to-current-page-after-sign-in https://github.com/plataformatec/devise/wiki/How-To:-Redirect-back-to-current-page-after-sign-in
Notice the filter in the wiki page needs to be added before you invoke Devise's authentication filters. 请注意,在调用Devise的身份验证过滤器之前,需要添加Wiki页面中的过滤器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.