rake routes:
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session DELETE /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /user devise_for :userss/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_user_registration GET /users/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"devise/registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
user_confirmation POST /users/confirmation(.:format) {:action=>"create", :controller=>"devise/confirmations"}
new_user_confirmation GET /users/confirmation/new(.:format) {:action=>"new", :controller=>"devise/confirmations"}
GET /users/confirmation(.:format) {:action=>"show", :controller=>"devise/confirmations"}
home_index GET /home/index(.:format) {:controller=>"home", :action=>"index"}
root / {:controller=>"home", :action=>"index"}
But if I click the logout link , I get
Routing Error
No route matches [GET] "/users/sign_out"
This is the application.html.erb:
<!DOCTYPE html>
<html> devise_for :users
<head>
<title>Rorblog</title>
<%= stylesheet_link_tag "application" %>
<%#= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<div id="container">
<div id="header">
<ul class="hmenu">
<li>
<%= link_to('Home', home_index_path ) %>
</li>
<% if user_signed_in? %>
<li>
<%= link_to('Logout', destroy_user_session_path, :method => :delete) %>
</li>
<li>
<%= link_to('Edit registration', edit_user_registration_path) %>
</li>
<% else %>
<li>
<%= link_to('Login', new_user_session_path) %>
</li>
<% end %>
</ul>
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
</div>
<div id="content">
<div id="loadwhat">
<%= yield %>
</div>
</div>
<div id="footer">
<%= "user1@copyright.com" %>
</div>
</div>
</body>
</html>
From page source I got:
<a href="/users/sign_out" data-method="delete" rel="nofollow">Logout</a>
The “rake routes” task shows the HTTP method that it will respond to in the second column. In the case of destroy_user_session_path, it only responds to the DELETE HTTP method. This is for safety as this is a destructive action, and different than a GET request. Ideally, web crawlers will not follow DELETE links because of their potential destructiveness.
As Arun Kumar Arjunan states, you will need to explicitly specify that this link should be executed with a DELETE method. By placing “:method => :delete” in your link, Rails UJS will convert this link to DELETE instead of a GET request, and follow the redirection from the server.
More information on HTTP methods here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
And more information on Rails UJS here: https://github.com/rails/jquery-ujs/wiki/Unobtrusive-scripting-support-for-jQuery