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?
It’s easy enough to do this if you’re using the unobtrusive rails plugins for jquery or [other js libs].
That can be made prettier by naming the route with
as: :signout, allowing you to usesignout_pathas the url helper.https://github.com/rails/jquery-ujs