您如何发送带有“删除”字样的请求HTTP动词?
我想在执行此操作的Rails应用程序的视图中创建一个链接...
I'd like to create a link in a view within a Rails application that does this...
DELETE /sessions
我该怎么做。
增加的复杂性:
会话资源没有模型,因为它代表用户登录会话。 创建
表示用户登录,销毁
表示注销。
The "session" resource has no model because it represents a user login session. CREATE
means the user logs in, DESTROY
means logs out.
这就是为什么URI中没有ID参数的原因。
That's why there's no ID param in the URI.
我正在尝试在UI中实现注销链接。
I'm trying to implement a "log out" link in the UI.
正确,浏览器实际上不支持发送删除请求。许多Web框架公认的约定是将_method参数设置为'DELETE',并使用POST请求。
Correct, browsers don't actually support sending delete requests. The accepted convention of many web frameworks is to send a _method parameter set to 'DELETE', and use a POST request.
下面是Rails中的一个示例:
Here's an example in Rails:
<%= link_to 'log out', session_path, :method => :delete %>
您可能想看看静态身份验证。