ruby-on-railsdevise

No route matches [GET] "user/sign_out" rails 5


I am currently getting this error using Devise and I have tried multiple things from other questions in order to resolve it with ZERO luck.

I was first advised to make sure I add the method as a delete:

<%= link_to "Logout", destroy_user_session_path, :method => :delete, :class => 'navbar-link'  %>

No luck.

Then I was advised that I needed to include in my layout header this:

<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>

or this:

<%= javascript_include_tag :defaults %>

Still... no luck.

Lastly I was advised to change in my /config/initializers/devise.rb file to change config.sign_out_via = :delete to config.sign_out_via = :get

No luck at all.

I am not sure what more to try,

here is my current code in my HTML, let me know if you need to see my routes to better assist you.

    <!DOCTYPE html>
<html>
<header>
  <h2><span>Anume*</span></h2>
  <img id='header' src="http://wallpapercave.com/wp/hkWe2SK.jpg" alt="" />



</header>
  <head>
    <title>Anume</title>
    <%= csrf_meta_tags %>

    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
  </head>

<body>
<p class="navbar-text pull-right">
    <% if user_signed_in? %>
    Logged in as
    <strong><%= current_user.email %></strong>.
    <%= link_to 'Edit profile', edit_user_registration_path, :class => 'navbar-link' %>
    |
    <%= link_to "Logout", destroy_user_session_path, :method => :delete, :class => 'navbar-link'  %>
    <% else %>
    <%= link_to "Sign up", new_user_registration_path, :class => 'navbar-link'  %>
    |
    <%= link_to "Login", new_user_session_path, :class => 'navbar-link'  %>
    <% end %>
</p>
</body>

here are my rails route for the logout function:

destroy_user_session DELETE /users/sign_out(.:format)    devise/session#destroy

Solution

  • one thing that I like to do on my

    /config/initializers/devise.rb is change from config.sign_out_via = :delete to config.sign_out_via = [:delete, :get] so you have both scenarios cover incase the delete method does not hit.

    open your console and make sure that jquery and jquery_ujs load properly

    let me share my setup with you

    in my assets application.js I have

    #app/assets/javascripts/application.js
    //= require jquery
    //= require jquery_ujs
    //= require turbolinks
    

    now on my layout

    #app/views/layouts/application.html.haml
    !!!
    %html{:lang => "en"}
      %head
        %meta{:charset => "utf-8"}/
        %meta{:content => "IE=edge", "http-equiv" => "X-UA-Compatible"}/
        %meta{:content => "width=device-width, initial-scale=1", :name => "viewport"}/
        %title
          Best Site Ever
        = csrf_meta_tags
        = stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload'
        = javascript_include_tag 'application', 'data-turbolinks-track': 'reload'
    
      %body
        - if current_user
          = link_to destroy_user_session_path, :method => :delete do
            Logout
    

    I hope that this is able to help