Reputation: 2889
I am trying to implement a HTTP delete request from the user. So I got this in my HTML file,
<li><a href="/signout">Logout</a></li>
but in my routes file I got this:
match '/signout', to: 'sessions#destroy', via: :delete
and destroy is defined as:
def destroy
sign_out
redirect_to root_path
end
if I remove "via: delete" seems to work fine. But how do I invoke a DELETE method using HTML?
Upvotes: 1
Views: 141
Reputation: 17408
It's easy enough to do this if you're using the unobtrusive rails plugins for jquery or [other js libs].
<li><%= link_to "Logout", '/signout', method: :delete %></li>
That can be made prettier by naming the route with as: :signout
, allowing you to use signout_path
as the url helper.
https://github.com/rails/jquery-ujs
Upvotes: 1
Reputation: 9587
See Is it possible to trigger an HTTP DELETE request from an HTML form?.
Basically you need to do it via XMLHttpRequest
.
Upvotes: 0