1

So, I'm getting the below error when clicking on Sign Out on my drop down menu on the nav:

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

However, this only happens when using the sign out on the drop down nav (the hamburger menu for mobile devices) and not when clicking the sign out on the regular nav.

See the code below:

  <div class="container demo-5">
    <div class="main clearfix">
      <div class="column">
        <div id="dl-menu" class="dl-menuwrapper">
          <button class="dl-trigger">Open Menu</button>
          <ul class="dl-menu dl-menu-toggle">
            <div id="closebtn"  onclick="closebtn()"></div>
            <% if user_signed_in? %>
            <li><%= link_to 'FAQ', faq_path %></li>
            <li><a href="#">Contact Us</a></li>
            <li><%= link_to 'My Account', account_path %></li>                    
            <li><%= link_to 'Sign Out',  destroy_user_session_path, method: 'delete' %></li> <--- this is the line
            <% else %>
            <li><%= link_to 'FAQ', faq_path %></li>
            <li><a href="#">Contact Us</a></li>
            <li><%= link_to 'Sign In', new_user_session_path %></li>
            <li><%= link_to 'Free Trial', plans_path %></li>
            <% end %>
          </ul>
        </div><!-- /dl-menuwrapper -->
      </div>
    </div>
  </div><!-- /container -->
</div>

And this is the non-drop down code that works:

  <div class="signincontainer pull-right">
        <div class="navbar-form navbar-right">
          <% if user_signed_in? %>
            <%= link_to 'Sign out', destroy_user_session_path, class: 'btn signin-button', method: :delete %>
              <div class="btn signin-button usernamefont"><%= link_to current_user.full_name, account_path %></div>
          <% else %>
....rest of code here

Updated error:

ActionController::RoutingError (No route matches [GET] "/user/sign_out"):
  actionpack (4.0.4) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.0.4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.4) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.4) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.0.4) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.0.4) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.0.4) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.0.4) lib/rails/rack/logger.rb:20:in `call'
  quiet_assets (1.0.2) lib/quiet_assets.rb:18:in `call_with_quiet_assets'
  actionpack (4.0.4) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/ru
Andrew Marshall
  • 89,426
  • 20
  • 208
  • 208
user3399101
  • 1,297
  • 3
  • 13
  • 25
  • 1
    it matches `DELETE /user/sign_out` – apneadiving Jun 07 '14 at 19:56
  • Right cheers!, so how do I fix this? I have method: 'delete', Thanks! – user3399101 Jun 07 '14 at 19:58
  • Hey, the model User was created by the scaffolding generator? If it wasn't, you will need provide the routes at config/routes.rb (Btw, is kind weird because your url contains user instead users.) – tehAnswer Jun 07 '14 at 20:06
  • It contains user instead of users because I have the following: devise_for :users, :path => "user". Please help me get this working! Thanks! – user3399101 Jun 07 '14 at 20:24

3 Answers3

2

The method specified must be a symbol.

In the code that's not working, it's currently a string:

link_to 'Sign Out', destroy_user_session_path, method: 'delete' 

In the code that's working, it's correctly specified as a symbol:

link_to 'Sign out', destroy_user_session_path, method: :delete
colinm
  • 4,062
  • 20
  • 17
  • Thanks @colinm ! Unfortunately, that still didn't help - still getting the same error.. What else could it be? Cheers! – user3399101 Jun 08 '14 at 16:03
1

@colinm's answer is right; but let me explain why:

--

HTTP Verbs

Devise sets a series of RESTful routes when you install it. Of al the routes it generates, there is destroy_user_session_path, which uses the delete HTTP Verb:

 destroy_user_session DELETE /users/sign_out   {controller:"devise/sessions", action:"destroy"}

This means this route is only available when you use the delete method in your link_to method, like this:

<%= link_to "Log Out", destroy_user_session_path, method: :delete %>

HTML defaults to the GET HTTP Verb, meaning if you don't explicitly define method: :delete in your code, Rails is not going to look for the right verb for the route

Richard Peck
  • 73,250
  • 8
  • 84
  • 139
  • Thanks Rich! Unfortunately, that still didn't help - still getting the same error.. What else could it be? Cheers! – user3399101 Jun 08 '14 at 16:01
  • You're still getting the error? Have you tried restarting the server? – Richard Peck Jun 08 '14 at 16:27
  • Yup I have. This is certainly an un-usual issue. I think it has something to do with the way that the code is being executed inside of the drop down menu, versus the way it's being executed on the regular nav. Any ideas? Cheers! – user3399101 Jun 08 '14 at 19:25
  • So, I've placed the same line of code "
  • " directly under the "Open Menu" line instead and it worked, but when it's inside the menu it doesn't work... Please help! – user3399101 Jun 08 '14 at 19:29
  • lol what's the difference with the menu? Is it in a partial or anything? – Richard Peck Jun 08 '14 at 19:48
  • No,the only difference is that it's in a toggle menu, using js. – user3399101 Jun 08 '14 at 20:49
  • That's weird. Any errors in the browser's console? If you view source (or the DOM tree if you're using turbolinks), is everything generating the same HTML for the signout link? – colinm Jun 08 '14 at 21:33