I have the following routes:
I'm developing an exercise tracking app and I want to have tracked_exercises
for the currently logged in user. This is my routes.rb
file:
Rails.application.routes.draw do
resources :exercises
devise_for :users
resources :users do
resources :tracked_exercises
end
root to: 'exercises#index'
end
However when I'm trying to log the current user out with <%= link_to "Logout", destroy_user_session_path, method: :delete, class: "navbar-link" %>
I first run into an error that says Uninitialized constant UsersController
.
Then after creating it, it turns out the redirection points the users to users/show
, and after having this controller, the logout never works:
class UsersController < ApplicationController
def show
redirect_to root_path
end
end
Am I doing something wrong with the way I've set devise up?
Thanks!
method: :delete
for links was a Rails UJS thing.
<%= link_to "Logout", destroy_user_session_path,
data: {turbo_method: :delete}
%>
# or better use a form
<%= button_to "Logout", destroy_user_session_path,
method: :delete
%>