我已经在我的应用程序上安装了设计,并在我的application.html.erb文件中应用了以下内容:

<div id="user_nav">
    <% if user_signed_in? %>
        Signed in as <%= current_user.email %>. This cannot be cheese?
        <%= link_to 'Sign out', destroy_user_session_path %>
    <% else %>
        <%= link_to 'Register', new_user_registration_path %> or <%= link_to 'Sign in', new_user_session_path %>
    <% end %>
</div>

我运行了rake路由,确认所有路由都是有效的。

同样,在我的路线上。我有belonge_for:users和root:to => "home#index"。

当点击“签出”链接时,我得到以下路由错误:

No route matches "/users/sign_out"

知道是什么导致了这个错误吗?


当前回答

对我来说,就是remove:method =>:delete

<%= link_to('Sign out', destroy_user_session_path) %>

其他回答

问题开始于rails 3.1…在/app/assets/javascript/中查找application.js。

如果文件不存在,创建一个文件名,我不知道为什么我的文件消失了,或者从来没有在“rails new app”....上创建

该文件是jquery....的实例

这个问题已经有很多答案了。对我来说,问题有两个方面:

when I expand my routes: devise_for :users do get '/users/sign_out' => 'devise/sessions#destroy' end I was getting warning that this is depreciated so I have replaced it with: devise_scope :users do get '/users/sign_out' => 'devise/sessions#destroy' end I thought I will remove my jQuery. Bad choice. Devise is using jQuery to "fake" DELETE request and send it as GET. Therefore you need to: //= require jquery //= require jquery_ujs and of course same link as many mentioned before: <%= link_to "Sign out", destroy_user_session_path, :method => :delete %>

只有一个例外,杰西的回答对我很管用:

<%= link_to "Sign out", destroy_user_session_path, :method => :delete %>

变化:

:delete

... :

'delete'

所以对我有用的代码是:

<%= link_to "Sign out", destroy_user_session_path, :method => 'delete' %>

我正在使用rails。所以这就是我必须要做的。重要的位是data: {turbo_method::delete}

<%= link_to t('nav.logout'), destroy_user_session_path, class: "nav-link", data: { turbo_method: :delete } %>

下面是rails在生成项目时创建的默认值。

application.html.erb

<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>

application.js

import "@hotwired/turbo-rails"
import "./controllers"
import * as bootstrap from "bootstrap"

如果你使用的是Rails 3.1,确保你的application.html.erb签出如下所示:

<%= link_to "Sign out", destroy_user_session_path,:method =>:delete %>

你的javascript包含行如下所示

<%= javascript_include_tag 'application' %>

我的猜测是一些宝石覆盖了default.js位置的新结构。