1

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?

Test Test
  • 2,831
  • 8
  • 44
  • 64

2 Answers2

1

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

noodl
  • 17,143
  • 3
  • 57
  • 55
0

See Is it possible to trigger an HTTP DELETE request from an HTML form?.

Basically you need to do it via XMLHttpRequest.

Community
  • 1
  • 1
Irfy
  • 9,323
  • 1
  • 45
  • 67
  • http://ruby.railstutorial.org/, I am following this tutorial, that's why I was wondering why the guys chose to write "via:delete" – Test Test Mar 16 '12 at 17:05