[英]Rails/Devise - sign_out not working in Safari
I am using the Devise gem for user authentication in my Rails app. 我在Rails应用程序中使用Devise gem进行用户身份验证。 I am finding that the sign_out
helper method is not working in Safari, both desktop and mobile - it works just fine in Chrome, etc. 我发现sign_out
帮助程序方法在Safari(无论是台式机还是移动设备)中均无法使用-在Chrome等系统中也能正常工作。
I am trying to force a signed in user to sign out when they hit a particular controller action: 我试图强制已登录的用户在遇到特定的控制器操作时退出:
def new
if user_signed_in?
sign_out
end
end
But this has no effect. 但这没有效果。 The user_signed_in?
user_signed_in?
and destroy_user_session_path
functionality work ok in the views, as in 在视图中, destroy_user_session_path
功能正常,如
<% if user_signed_in? %>
<%= link_to('Logout', destroy_user_session_path, :method => :delete) %>
<% end %>
but calling sign_out
from the controller is a no-go. 但是从控制器调用sign_out
是不行的。
Has anyone experienced these kinds of cross-browser issues with Devise, and is there a way that I can fix this or otherwise achieve the same functionality? 有没有人在Devise中遇到过这类跨浏览器的问题,有没有办法我可以解决此问题或以其他方式实现相同的功能?
Go in config/application.rb and set serve_static_assets
by true
进入config / application.rb并通过true
设置serve_static_assets
config.serve_static_assets = true
Or 要么
Add to routes.rb 添加到routes.rb
match '/logout' => 'devise/sessions#destroy', :via => [:delete]
Then, your link for sign out should be like this 然后,您的退出链接应如下所示
<%= link_to 'Sign Out', logout_path %>
If it doesn't work, try overriding the Devise::SessionsController like this: 如果不起作用,请尝试像这样重写Devise :: SessionsController:
class SessionsController < Devise::SessionsController
def log_out
user = current_user
sign_out user
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.