[英]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. 没有路线匹配“ / users / sign_out”。登录后,我只是按照ryan bates教程进行操作。 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. 如果您想知道为什么,请使用devise查阅本安装指南中有关rails 3.1的部分。 Basically, when you try to HTTP GET the sign out route, it doesn't exist because it's only setup for HTTP DELETE. 基本上,当您尝试通过HTTP GET退出路由时,该路由不存在,因为它只是为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. 同样在该教程中,您可以看到如何设置设计以使其在测试模式下使用GET方法。 Change /config/initializers/devise.rb as follows: 更改/config/initializers/devise.rb,如下所示:
# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = Rails.env.test? ? :get : :delete
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.