0

I just set up devise for my Rails application. It was with the "user" model.

When I look at the routes created, I can see :

destroy_user_session DELETE /users/sign_out(.:format)      devise/sessions#destroy

Though, no script intended to destroy the session has been created when I installed Devise.

I'm a little bit lost there...do I have to create this script ? If yes, where do I have to put it ? In the views ? But is it really a view ?

And last but not least, what do I have to put in it ?

Thank you a lot.

Zoz
  • 279
  • 1
  • 3
  • 9

2 Answers2

1

No you do not have to write a script for destroy_user_session. This is handled by the destroy action of the devise's SessionsController which is already available since you've installed devise gem. unless you want to change the default behavior of destroy action, all you need is a link to the action on your view to destroy the session like this:

<%= link_to 'Sign out', destroy_user_session_path, :method => :delete %> and devise will destroy the current session

Optimus Pette
  • 2,810
  • 2
  • 23
  • 44
  • Oh well where were you able to find this information ? When I try this, I receive this message : No route matches [GET] "/users/sign_out" It seems that Chrome is trying to make a GET request instead of a DELETE... – Zoz Aug 06 '13 at 13:40
  • And when I try to do the request manually with curl, the session is still active... – Zoz Aug 06 '13 at 13:46
  • first run rake routes and confirm the presence of `destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy` – Optimus Pette Aug 06 '13 at 13:50
  • 1
    I can see from your post that you already have the route to `devise/sessions#destroy` but you can check another solution here [link](http://stackoverflow.com/questions/6567863/no-route-matches-get-users-sign-out) – Optimus Pette Aug 06 '13 at 14:02
0

Devise is an engine, so you have proper controller (Devise::SessionsController) that handle this request in devise gem code. That means this route should work out of the box.

Devise github page (with tutorial) here: https://github.com/plataformatec/devise

More about Rails engines here: http://guides.rubyonrails.org/engines.html

Marek Lipka
  • 48,573
  • 7
  • 81
  • 87
  • I've followed this tutorial but it is just told to generate devise model and views... And routes have been created for sign_out but no code was intended to actually destroy the session. – Zoz Aug 06 '13 at 12:55
  • @Zoz Model - yes. Views - not. Generating devise views is not obligatory. – Marek Lipka Aug 06 '13 at 12:58