Skip to content

Instantly share code, notes, and snippets.

@Matt-Yorkley
Last active April 28, 2022 07:12
Show Gist options
  • Save Matt-Yorkley/b333cb7d61827aee8f8f5d111567bac8 to your computer and use it in GitHub Desktop.
Save Matt-Yorkley/b333cb7d61827aee8f8f5d111567bac8 to your computer and use it in GitHub Desktop.
Devise workarounds
# app/views/example/logout_button.html.erb
<%= link_to "Log out", link_to destroy_user_session_path, method: :delete %>
# app/config/routes.rb
Rails.application.routes.draw do
root to: "home#index"
devise_for :users, controllers: {
sessions: "users/sessions" # Override the sessions controller
}
end
# app/controllers/users/sessions_controler.rb
class Users::SessionsController < Devise::SessionsController
# DELETE /resource/sign_out
def destroy
# Redirect after a sign-out is successfully performed. The button has a 204 response
# that doesn't redirect or render, which doesn't play nicely with Turbo-style navigation.
# The destroy method in the parent takes a block that allows some minor customisation.
super do
return redirect_to root_path
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment