没有路线与[GET]“ / logout”匹配。 [铁轨]

编程入门 行业动态 更新时间:2024-10-08 02:28:10
本文介绍了没有路线与[GET]“ / logout”匹配。 [铁轨]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

单击注销时,出现以下路由错误:

I get the following routing error when I click on "logout":

No route matches [GET] "/logout"

这是我的application.html.erb文件:

This is my application.html.erb file:

<% if session[:user_id] %> <%= link_to 'Logout', logout_path, :method => :delete %> <% end %>

这是我的route.rb文件:

This is my routes.rb file:

get 'admin' => 'admin#index' controller :sessions do get 'login' => :new post 'login'=> :create delete 'logout' => :destroy end get "sessions/create" get "sessions/destroy"

有人知道如何解决此问题吗?

Does anybody know how to solve this problem?

推荐答案

您启用了内置在所需的JavaScript库中( jquery / jquery_ujs )?浏览器不直接支持 delete 方法,因此最终会创建一个带有隐藏字段 _method 的表单, Rails会将其引导到正确的位置。

Have you enabled the built-in JavaScript libraries that are required (jquery/jquery_ujs)? The delete method is not directly supported by browsers, so this ends up actually creating a form with a hidden field _method, that Rails interprets to direct you to the correct place.

编辑:

要启用这些库,请检查您的应用程序布局文件。通常位于 app / views / layouts / application.html.erb ,但是如果您自定义应用程序,则可能会有所不同。

To enable these libraries, check your application layout file. This is usually located at app/views/layouts/application.html.erb, but this may vary if you've customised your app.

您需要在头部分具有以下标签:

You'll need to have the following tags in the head section:

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>

这应该可以为您工作,但如果没有,请发回邮件,我会尽力帮助您进一步。如果您可以在GitHub或其他地方使代码在线,这将很有用,这样我们就可以在上下文中看到您要执行的操作。

That should get this working for you, but if not, post back and I'll try to help further. It'd be useful if you could get your code online - on GitHub or somewhere else - so that we can all see what you're trying to do in context.

更多推荐

没有路线与[GET]“ / logout”匹配。 [铁轨]

本文发布于:2023-11-25 21:37:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631442.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:铁轨   路线   logout

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!