简体   繁体   中英

Rails 3 Devise - Getting “ No route matches ”/users/sign_out“ ”

No route matches "/users/sign_out" When I am logged in. I just followed ryan bates tutorial to get devise working. My rake routes looks like this.

       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    /users/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"}
                    root        /(.:format)                    {:controller=>"welcome", :action=>"index"}

Thanks in advance.

Routes look correct. Your sign out link should look like this:

<%= link_to('Logout', destroy_user_session_path, :method => :delete) %>

I assume the other answer solved your problem. If you want to know why, check out the section in this setup guide for rails 3.1 with devise. Basically, when you try to HTTP GET the sign out route, it doesn't exist because it's only setup for HTTP DELETE. You can see this in the second column of the routes you pasted in the question. Probably your links were missing the

:method => :delete

Also in that tutorial, you can see how to setup devise to use the GET method when it is in test mode. Change /config/initializers/devise.rb as follows:

# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = Rails.env.test? ? :get : :delete

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM