1

I'm using Devise for authentication and creating an item in a dropdown for Sign Out. This is how I've built it:

<a href="<%= url_for(destroy_user_session_path) %>"><span data-icon="&#xe040;" /> Sign Out</a>

I'm using an icon font to stick a nice little image in to the left of the text. With Devise, it uses the DELETE verb for the destroy_user_session_path route. Most people would use a button_to or link_to but I don't think this will work for me. Using link_to is going to stick in the closing tag automatically, which won't allow me to put my span tag in. Is there a way for me to build the above link and use the DELETE verb?

For now I'm using the solution in this thread. Specifically changing config.sign_out_via = :delete to config.sign_out_via = :get in devise.rb.

Community
  • 1
  • 1
Ryan Arneson
  • 1,323
  • 3
  • 14
  • 25

1 Answers1

1

Just add data-method="delete" to your link tag. This is what link_to does when you call it with :method => :delete. JQuery does the rest of the work.

<a href="<%= url_for(destroy_user_session_path) %>" data-method="delete"><span data-icon="&#xe040;" /> Sign Out</a>
aromero
  • 25,681
  • 6
  • 57
  • 79