简体   繁体   中英

Rails/Devise - sign_out not working in Safari

I am using the Devise gem for user authentication in my Rails app. 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.

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? and destroy_user_session_path functionality work ok in the views, as in

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

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?

Go in config/application.rb and set serve_static_assets by true

config.serve_static_assets = true

Or

Add to 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:

class SessionsController < Devise::SessionsController
 def log_out
  user = current_user
  sign_out user
 end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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