设计无路由匹配[GET] QUOT; /用户/ SIGN_OUT"从删除指定的链接 [英] Devise No route matches [GET] "/users/sign_out" from link with delete specified

查看:146
本文介绍了设计无路由匹配[GET] QUOT; /用户/ SIGN_OUT"从删除指定的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我环顾四周,一个解决这个问题,最好像说已经没有做什么来解决我的问题是一样的。我指定的链接删除方法,但路由错误是说这是一个GET请求。任何想法,为什么下面的链接也将结束作出首要/忽略方法声明?

 <%=的link_to注销,destroy_user_session_path,:方法=> :删除%>

路线

  devise_for:用户做
    得到'注销'=> 会话#灭',:如=> :destroy_user_session
    得到'登录'=> 色器件/会话#新的
  结束


解决方案

不要使用GET,因为它可能让你暴露CSFR,这是不是在这种情况下,交易的是什么大不了的销毁会话 - 但仍然不是一个很好的事情)。而且,它不遵循REST约定。


如果您在使用SSL的设计路线,发生的事情是当你尝试从HTTP网址注销,它的正确发送DELETE请求,但后来通过GET重定向到的https版本。

通过添加修复此的(协议:'HTTPS')应用于登出的URL,如下所示:

  =的link_to注销,destroy_user_session_url(协议:HTTPS),方法:删除

请注意:使用网址,而不是路径是很重要的。

希望有所帮助。

So I looked around for a solution to this issue and most seem to say the same thing which hasn't done much to solve my problem. I've specified the delete method in the link but the routing error is saying it was a GET request. Any ideas why the link below would wind up making a overriding/ignoring the method declaration?

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

Routes

  devise_for :users do
    get 'logout' => 'sessions#destroy', :as => :destroy_user_session
    get 'login' => 'devise/sessions#new'
  end

解决方案

Don't use GET to destroy a session because it opens you up to CSFR, which isn't that big deal of a deal in this case - but still not a good thing to do). And, it doesn't follow REST conventions.


If you're using SSL for Devise routes, what's happening is when you try to sign out from an 'http' url, it's sending a DELETE request properly but then redirecting to the 'https' version via GET.

Fix this by adding (protocol: 'https') to the sign out url like so:

= link_to "Logout", destroy_user_session_url(protocol: 'https'), method: :delete

Note: it's important to use 'url' instead of 'path'.

Hope that helps.

这篇关于设计无路由匹配[GET] QUOT; /用户/ SIGN_OUT&QUOT;从删除指定的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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