我已经在我的应用程序上安装了设计,并在我的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"

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


当前回答

有很多解决方案。但主要是用这个,

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

或者配置设计。Rb使用正确的sign_out方法

在devise.rb

config.sign_out_via = :delete ( or  :get which u like to use.) 

其他回答

看看你的路线。Rb有一个“resource:users”在“belonge_for:users”之前,然后尝试交换它们:

作品 devise_for:用户 资源:用户 失败 资源:用户 devise_for:用户

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

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 %>

我在设计中修改了这一行。

config.sign_out_via = :delete

to

config.sign_out_via = :get

它开始对我有用。

有很多解决方案。但主要是用这个,

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

或者配置设计。Rb使用正确的sign_out方法

在devise.rb

config.sign_out_via = :delete ( or  :get which u like to use.) 

如果你使用的是HTTPS,如果你的签出链接是不安全的版本,它就会崩溃。在后端,它重定向到安全版本。这个重定向是一个GET,它导致了这个问题。

确保你的链接使用HTTPS。你可以在你的url助手中强制使用协议:“https”(确保你使用url助手而不是路径助手)。

<%= link_to "Sign out", destroy_user_session_url(protocol: "https"), method: :delete %>