Reputation: 25768
<a rel="nofollow" data-method="delete" href="/users/sign_out">Sign Out</a>
Read some code usign devise, I noticed sign_out link has two special attributes
data-method="delete", I am wondering if this is the standard attribute in html5?
Upvotes: 0
Views: 53
Reputation: 76784
Code Different
is right, that code is an HTML5 data attribute. However, it represents "method
", which is not limited to HTML5 -- it's just that Rails takes methods other than GET
/POST
and appends them to the request with jquery:
The way it works is that, when the link is activated, [Rails] constructs a hidden form in the document with the "action" attribute corresponding to "href" value of the link and the method corresponding to "data-method" value, and submits that form.
Note for non-Rails backends: because submitting forms with HTTP methods other than GET and POST isn't widely supported across browsers, all other HTTP methods are actually sent over POST with the intended method indicated in the "_method" parameter
HTTP uses methods
(calls them verbs
) to give the developer scope on how to manage requests in the backend. This is a core principle of HTTP, a REST protocol.
In short - although what you're asking is a custom HTML5 data attribute, the underlying functionality is present in all HTTP-enabled front-ends; it's just that you have to append the methods to the request (as in this instance) because standard HTML doesn't support PUT
/PATCH
/DELETE
outright.
Upvotes: 0
Reputation: 93191
It's HTML5 custom data attribute. Your code defined an attribute called method
with the value of delete
.
Upvotes: 1