没有路线与[GET]“ / logout”匹配。 [铁轨] [英] No route matches [GET] "/logout" [rails]

查看:66
本文介绍了没有路线与[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”匹配。 [铁轨]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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