没有路由匹配“/users/sign_out";设计导轨 3 [英] No route matches "/users/sign_out" devise rails 3

查看:30
本文介绍了没有路由匹配“/users/sign_out";设计导轨 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

<% if user_signed_in?%>以 <%= current_user.email %> 的身份登录.这不能是奶酪吗?<%= link_to '退出',destroy_user_session_path %><%其他%><%= link_to '注册', new_user_registration_path %>或 <%= link_to '登录', new_user_session_path %><%结束%>

我运行了 rake routes 并确认所有路由都是有效的.

此外,在我的 routes.rb 文件中,我有 devise_for :usersroot :to =>家#index".

我在单击退出"链接时收到以下路由错误:

没有路由匹配/users/sign_out"

知道导致错误的原因是什么吗?

解决方案

我认为退出的途径是一个 DELETE 方法.这意味着您的注销链接需要如下所示:

<%= link_to "退出", destroy_user_session_path, :method =>:删除%>

你的不包括 :method =>:delete 部分.另外,请注意,要使其正常工作,您还必须在布局文件 (application.html.erb) 中包含 <%= javascript_include_tag :defaults %>.

I've installed devise on my app and applied the following in my application.html.erb file:

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

I ran rake routes and confirmed that all the routes are valid.

Also, in my routes.rb file I have devise_for :users and root :to => "home#index".

I get the following routing error when clicking the "Sign out" link:

No route matches "/users/sign_out"

Any ideas what's causing the error?

解决方案

I think the route for signing out is a DELETE method. This means that your sign out link needs to look like this:

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

Yours doesn't include the :method => :delete part. Also, please note that for this to work you must also include <%= javascript_include_tag :defaults %> in your layout file (application.html.erb).

这篇关于没有路由匹配“/users/sign_out";设计导轨 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆