I've installed devise on my app and applied the following in my application.html.erb
file:
<div id="user_nav">
<% if user_signed_in? %>
Signed in as <%= current_user.email %>. This cannot be cheese?
<%= link_to 'Sign out', destroy_user_session_path %>
<% else %>
<%= link_to 'Register', new_user_registration_path %> or <%= link_to 'Sign in', new_user_session_path %>
<% end %>
</div>
I ran rake routes
and confirmed that all the routes are valid.
Also, in my routes.rb
file I have devise_for :users
and root :to => "home#index"
.
I get the following routing error when clicking the "Sign out" link:
No route matches "/users/sign_out"
Any ideas what's causing the error?
If you are using Rails 3.1 make sure your application.html.erb sign out looks like:
<%= link_to "Sign out", destroy_user_session_path, :method => :delete %>
And that your javascript include line looks like the following
<%= javascript_include_tag 'application' %>
My guess is that some gems overwrite the new structure of the default.js location.
I had the same problem with rails 3.1.0, and I solved adding in file the followings lines:
the
':method => :delete
' in page is 'data-method="delete"
' so your page must have jquery_ujs.js, it will submit link with method delete not method getUse it in your routes.rb file:
Many answers to the question already. For me the problem was two fold:
when I expand my routes:
I was getting warning that this is depreciated so I have replaced it with:
I thought I will remove my jQuery. Bad choice. Devise is using jQuery to "fake" DELETE request and send it as GET. Therefore you need to:
and of course same link as many mentioned before:
Most answers are partial. I have hit this issue many times. Two things need to be addressed:
the delete method needs to be specified
Then devise uses jquery, so you need to load those
and ensure that BOTH jquery and jquery-ujs are specified in your myDirectiveJSfile.js