简体   繁体   中英

Rails Devise : session#destroy missing

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM