简体   繁体   English

在Rails 3.1中设计路线问题,没有路线匹配[GET]“ / users / sign_out”

[英]Devise routes issue in Rails 3.1 with No route matches [GET] “/users/sign_out”

I am using the Devise 1.4.9 authentication gem with my Rails 3.1 app and when I click on any link I get routing errors. 我在我的Rails 3.1应用程序中使用了Devise 1.4.9身份验证gem,当我单击任何链接时,都会出现路由错误。 Here's what happens when I click on the Sign Out link: 单击“注销”链接时,将发生以下情况:

Routing Error

No route matches [GET] "/users/sign_out"

I am creating the link with this method: 我正在使用此方法创建链接:

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

This is how the link is rendered in the source: 这是链接在源中的呈现方式:

<a href="/users/sign_out" data-method="delete" rel="nofollow">Sign Out</a>

I have this line in my layout header: 我的布局标题中有以下一行:

<%= javascript_include_tag :defaults %>

These lines are in my application.js file: 这些行在我的application.js文件中:

//
// = require jquery
// = require jquery_ujs
// = require_tree .

Here is the relevant rake routes output: 这是相关的耙路输出:

          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"}

I've tried pretty much everything in this thread to no avail: 我已经尝试了该线程中的几乎所有内容,但都没有成功:

No route matches "/users/sign_out" devise rails 3 没有路线匹配“ / users / sign_out”设计导轨3

I've restarted the server numerous times. 我已经多次重启服务器。

This issue seems to have come up in the past, but not a single solution described has changed this behavior and I'm stumped. 这个问题似乎在过去出现过,但是没有一个描述的解决方案改变了这种行为,对此我感到很困惑。

Writing 写作

devise_scope :user do 
  get "/users/sign_out", :to => "devise/sessions#destroy" 
  end 

in my routes.rb solved the problem for me. 在我的routes.rb为我解决了这个问题。

One, you might want to use a button (can be styled to look like a link) for something destructive, as per this checklist for using GET . 一种,您可能希望使用按钮(可以将其样式化为看起来像链接)来破坏性,如使用GET此清单所示 That alone may fix it. 仅此一项就可以解决。

Two, you need the csrf_meta_tag in the file, which you probably already have. 第二,您需要文件中的csrf_meta_tag ,您可能已经拥有了。

Have you confirmed the JS files are actually being loaded? 您是否已确认JS文件实际上已被加载?

(I thought the // = with the space might be a problem, but apparently it works as well as //= as Rails creates by default.) (我认为带空格的// =可能是个问题,但显然它的效果和Rails默认创建的//=一样。)

如果将:defaults传递给javascript_include_tag ,请尝试将:defaults重命名为:application ,以防您在application.js定义包含内容

<%= javascript_include_tag :application %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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