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

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


当前回答

页面中的“:method =>:delete”是“data-method="delete"” 所以你的页面必须有jquery_ujs.js,它会用delete方法提交链接,而不是用get方法

其他回答

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

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

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

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

在github中查看源代码:

https://github.com/plataformatec/devise/commit/adb127bb3e3b334cba903db2c21710e8c41c2b40#lib/generators/templates/devise.rb(日期:2011年6月27日)

#用于签出资源的默认HTTP方法。默认为:get。 188 #配置。Sign_out_via =:get 187 #用于签出资源的默认HTTP方法。默认值为:delete。 188 配置。Sign_out_via =:delete

在你的路线上使用它。rb文件:

devise_for :users do
    get '/users/sign_out' => 'devise/sessions#destroy'
end

我在rails 3.1.0中遇到了同样的问题,我解决了在文件中添加以下行:

app/assets/javascripts/application.js
//= require_tree
//= require jquery
//= require jquery_ujs