简体   繁体   English

Rails Devise:缺少会话#destroy

[英]Rails Devise : session#destroy missing

I just set up devise for my Rails application. 我只是为Rails应用程序设置了设计。 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. 但是,在安装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 . 不,您不必为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. 这是由装置的SessionsController的destroy动作处理的,因为您已经安装了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: 除非您想更改destroy动作的默认行为,否则您需要的是指向视图上的动作的链接,以销毁会话,如下所示:

<%= link_to 'Sign out', destroy_user_session_path, :method => :delete %> and devise will destroy the current session <%= link_to 'Sign out', destroy_user_session_path, :method => :delete %>并设计将破坏当前会话

Devise is an engine, so you have proper controller ( Devise::SessionsController ) that handle this request in devise gem code. Devise是一个引擎,因此您有合适的控制器( Devise::SessionsController )可在devise gem代码中处理此请求。 That means this route should work out of the box. 这意味着该路线应该开箱即用。

Devise github page (with tutorial) here: https://github.com/plataformatec/devise 在此处设计github页面(含教程): https : //github.com/plataformatec/devise

More about Rails engines here: http://guides.rubyonrails.org/engines.html 有关Rails引擎的更多信息,请访问: http : //guides.rubyonrails.org/engines.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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