我正在使用设计
sign_in
和sign_up
网址正在运作
但是,
当我尝试网址时:http://localhost:3000/users/sign_out
它会生成路由错误
No route matches [GET] "/users/sign_out"
我该如何解决这个问题?
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 /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"}
status_message_index GET /status_message(.:format) {:action=>"index", :controller=>"status_message"}
POST /status_message(.:format) {:action=>"create", :controller=>"status_message"}
new_status_message GET /status_message/new(.:format) {:action=>"new", :controller=>"status_message"}
edit_status_message GET /status_message/:id/edit(.:format) {:action=>"edit", :controller=>"status_message"}
status_message GET /status_message/:id(.:format) {:action=>"show", :controller=>"status_message"}
PUT /status_message/:id(.:format) {:action=>"update", :controller=>"status_message"}
DELETE /status_message/:id(.:format) {:action=>"destroy", :controller=>"status_message"}
home /home(.:format) {:action=>"index", :controller=>"status_message"}
root / {:controller=>"home", :action=>"index"}
Microblog::Application.routes.draw do
devise_for :users, :controllers => {:migrations => "users/registrations"}
resources 'status_message'
match 'home' => 'status_message#index'
root :to => 'home#index'
end
答案 0 :(得分:41)
错误的原因是使用GET HTTP方法无法访问路由。请注意rake routes
输出中相关行的内容:
destroy_user_session DELETE /users/sign_out(.:format)
这意味着,如果要将用户注销,则需要向该URL发送DELETE请求。在rails中,您可以生成一个类似的链接:
link_to 'Sign out', destroy_user_session_path, :method => :delete
# alternatively (although NOT recommended):
link_to 'Sign out', '/users/sign_out', :method => :delete
重要的部分是:method => :delete
。请注意,浏览器实际上并不支持DELETE请求,rails实际上是在POST数据,但它会发送一个模拟DELETE方法的特殊参数。
这背后的原因是“退出”网址会将当前用户记录下来,这是一种破坏性操作。如果它可以通过浏览器自由访问,它可能会导致各种问题。 GET请求永远不应该改变服务器的状态。有关这方面的更多信息,这是一篇不错的维基百科文章:http://en.wikipedia.org/wiki/REST#RESTful_web_services
答案 1 :(得分:12)
上述任何建议对我都不起作用....
这篇文章对于找到其他替代方案更有用。 No route matches "/users/sign_out" devise rails 3
我必须在application.js文件中添加以下行
//= require_tree .
// Add following lines.
//= require jquery
//= require jquery_ujs
答案 2 :(得分:0)
我有完全相同的症状,但我也使用jquery-turbolinks与砌体轨道在网站过渡和位置“很好”的图像。
我发现这个“打破了”转变:
//= require jquery_ujs
所以我删除了它,过渡就像一个魅力...但当我去注销时,即使我的rake路线显示路径存在,我也得到了上述错误。
对我的“修复”结果是添加了// = require rails-ujs并重新安排了我的树,所以我最终得到了:
//= require rails-ujs
//= require jquery
//= require jquery.turbolinks
//= require twitter/bootstrap
//= require masonry/jquery.masonry
//= require masonry/jquery.imagesloaded.min
//= require masonry/modernizr-transitions
//= require turbolinks
//= require_tree .
顺便说一句,任何在砌体工作时发现此错误的人都应该在div中添加“transition-enabled infinite-scroll clearfix”,其中包含他们想要操作的资源的id ...在我的案例“bookads”
<div class="transitions-enabled" id="bookads">
<% @books.each do |book| %>
<div class="box panel panel-default">
<div class="panel-heading index">
<h3 class="panel-title text-center">
<strong><%= book.title %></strong>
</h3>
</div>
<div class="panel-body">... etc
请注意我使用的各个元素的ID称为“box”
在你的coffeescript中:
$ ->
$('#bookads').imagesLoaded ->
$('#bookads').masonry
itemSelector: '.box'
isFitWidth: true
isAnimated: true
并获得“平滑”动画我还添加了masonry / jquery.imagesloaded.min和masonry / modernizr-transitions,如上图所示。
希望这个答案可以节省我花在寻找解决方案上的几个小时。
答案 3 :(得分:0)
将其放入app / views / layouts / application.html.erb
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
希望对您有帮助