为什么我不能使用Devise注销用户?(Why can't I log out users using Devise?)

使用Rails 4.2并安装以下gem。

gem 'turbolinks' gem 'jquery-ui-rails' gem "devise_ldap_authenticatable"

除了点击我的注销链接外,我能说的一切都很好。

<%= link_to "Logout", destroy_user_session_path, method: :delete, :data => { :no_turbolink => true } %>

它正确地将用户重定向回到生产中的登录页面,但是如果我刷新了sign_in页面,我会发送回我的根页面并发出一条通知消息“你已经登录了”。 我对destroy_user_session_path的操作包含以下内容:

# DELETE /resource/sign_out def destroy cookies.delete(:auth_token) reset_session super end

当我在开发环境中执行相同的步骤时,一切正常,但在生产中我得到了上面描述的行为。 我也尝试过,正如一些帖子所建议的那样,将destroy从一个:delete方法更改为:get (即使这看起来非常不正确)但是这样做不起作用。 我还检查了我的application.html.erb中有以下行: <%= csrf_meta_tags %> - 确实如此。 最后这里是我的(可能太大)javascript列表包括...

//= require jquery //= require jquery-ui //= require jquery_ujs //= require jquery.turbolinks //= require jquery.tokeninput //= require jquery-ui/autocomplete // for bootstrap 4 add tether below //= require turbolinks //= require nprogress //= require nprogress-turbolinks //= require nested_form_fields //= require highcharts //= require highcharts/highcharts-more //= require highcharts/modules/exporting //= require bootstrap-sprockets //= require bootstrap-multiselect //= require_tree .

如果我忘了什么,请告诉我,我会把它包括在内。 谢谢!

更新(添加销毁操作)

# DELETE /resource/sign_out def destroy cookies.delete(:auth_token) reset_session super end

Using Rails 4.2 and having the following gems installed.

gem 'turbolinks' gem 'jquery-ui-rails' gem "devise_ldap_authenticatable"

Everything from what I can tell works fine, except when I click my logout link...

<%= link_to "Logout", destroy_user_session_path, method: :delete, :data => { :no_turbolink => true } %>

It properly redirects the user back to the sign in page on production, but If I refresh that sign_in page I'm sent back to the my root page with a notice message saying "You are already signed in.". My action for the destroy_user_session_path contains the following:

# DELETE /resource/sign_out def destroy cookies.delete(:auth_token) reset_session super end

When I do the same steps in my development environment everything works fine, but on production I get the behavior I described above. I also tried, as some posts have recommended, changing the destroy from a :delete method to a :get (even though this seems very incorrect) but that didn't work. I also checked that my application.html.erb had the following line in it: <%= csrf_meta_tags %> -- it does. And finally here's my (probably too massive) lists of javascript includes...

//= require jquery //= require jquery-ui //= require jquery_ujs //= require jquery.turbolinks //= require jquery.tokeninput //= require jquery-ui/autocomplete // for bootstrap 4 add tether below //= require turbolinks //= require nprogress //= require nprogress-turbolinks //= require nested_form_fields //= require highcharts //= require highcharts/highcharts-more //= require highcharts/modules/exporting //= require bootstrap-sprockets //= require bootstrap-multiselect //= require_tree .

If I forgot anything please let me know and I'll include it. Thanks!

Update (Added destroy action)

# DELETE /resource/sign_out def destroy cookies.delete(:auth_token) reset_session super end

最满意答案

也许尝试删除整个会话而不仅仅是auth_token。 我在上面使用相同的Devise设置,但devise_ldap_authenticator除外。 Rails 4

# app/controllers/sessions_controller.rb class SessionsController < ApplicationController def destroy session.delete(:user_id) end end

然后在视图中

# To log out <%= link_to "Log Out", destroy_user_session_path, :method => 'delete'%>

在我的gemfile中,我正在使用活动记录会话存储:

gem 'activerecord-session_store', github: 'rails/activerecord-session_store'

并在初始化器中

Rails.application.config.session_store :active_record_store

Maybe try deleting the entire session not just the auth_token. I'm using same Devise setup above with the exception of devise_ldap_authenticator. Rails 4

# app/controllers/sessions_controller.rb class SessionsController < ApplicationController def destroy session.delete(:user_id) end end

Then in the view

# To log out <%= link_to "Log Out", destroy_user_session_path, :method => 'delete'%>

In my gemfile i'm using active-record session-store:

gem 'activerecord-session_store', github: 'rails/activerecord-session_store'

And in an initializer

Rails.application.config.session_store :active_record_store为什么我不能使用Devise注销用户?(Why can't I log out users using Devise?)

使用Rails 4.2并安装以下gem。

gem 'turbolinks' gem 'jquery-ui-rails' gem "devise_ldap_authenticatable"

除了点击我的注销链接外,我能说的一切都很好。

<%= link_to "Logout", destroy_user_session_path, method: :delete, :data => { :no_turbolink => true } %>

它正确地将用户重定向回到生产中的登录页面,但是如果我刷新了sign_in页面,我会发送回我的根页面并发出一条通知消息“你已经登录了”。 我对destroy_user_session_path的操作包含以下内容:

# DELETE /resource/sign_out def destroy cookies.delete(:auth_token) reset_session super end

当我在开发环境中执行相同的步骤时,一切正常,但在生产中我得到了上面描述的行为。 我也尝试过,正如一些帖子所建议的那样,将destroy从一个:delete方法更改为:get (即使这看起来非常不正确)但是这样做不起作用。 我还检查了我的application.html.erb中有以下行: <%= csrf_meta_tags %> - 确实如此。 最后这里是我的(可能太大)javascript列表包括...

//= require jquery //= require jquery-ui //= require jquery_ujs //= require jquery.turbolinks //= require jquery.tokeninput //= require jquery-ui/autocomplete // for bootstrap 4 add tether below //= require turbolinks //= require nprogress //= require nprogress-turbolinks //= require nested_form_fields //= require highcharts //= require highcharts/highcharts-more //= require highcharts/modules/exporting //= require bootstrap-sprockets //= require bootstrap-multiselect //= require_tree .

如果我忘了什么,请告诉我,我会把它包括在内。 谢谢!

更新(添加销毁操作)

# DELETE /resource/sign_out def destroy cookies.delete(:auth_token) reset_session super end

Using Rails 4.2 and having the following gems installed.

gem 'turbolinks' gem 'jquery-ui-rails' gem "devise_ldap_authenticatable"

Everything from what I can tell works fine, except when I click my logout link...

<%= link_to "Logout", destroy_user_session_path, method: :delete, :data => { :no_turbolink => true } %>

It properly redirects the user back to the sign in page on production, but If I refresh that sign_in page I'm sent back to the my root page with a notice message saying "You are already signed in.". My action for the destroy_user_session_path contains the following:

# DELETE /resource/sign_out def destroy cookies.delete(:auth_token) reset_session super end

When I do the same steps in my development environment everything works fine, but on production I get the behavior I described above. I also tried, as some posts have recommended, changing the destroy from a :delete method to a :get (even though this seems very incorrect) but that didn't work. I also checked that my application.html.erb had the following line in it: <%= csrf_meta_tags %> -- it does. And finally here's my (probably too massive) lists of javascript includes...

//= require jquery //= require jquery-ui //= require jquery_ujs //= require jquery.turbolinks //= require jquery.tokeninput //= require jquery-ui/autocomplete // for bootstrap 4 add tether below //= require turbolinks //= require nprogress //= require nprogress-turbolinks //= require nested_form_fields //= require highcharts //= require highcharts/highcharts-more //= require highcharts/modules/exporting //= require bootstrap-sprockets //= require bootstrap-multiselect //= require_tree .

If I forgot anything please let me know and I'll include it. Thanks!

Update (Added destroy action)

# DELETE /resource/sign_out def destroy cookies.delete(:auth_token) reset_session super end

最满意答案

也许尝试删除整个会话而不仅仅是auth_token。 我在上面使用相同的Devise设置,但devise_ldap_authenticator除外。 Rails 4

# app/controllers/sessions_controller.rb class SessionsController < ApplicationController def destroy session.delete(:user_id) end end

然后在视图中

# To log out <%= link_to "Log Out", destroy_user_session_path, :method => 'delete'%>

在我的gemfile中,我正在使用活动记录会话存储:

gem 'activerecord-session_store', github: 'rails/activerecord-session_store'

并在初始化器中

Rails.application.config.session_store :active_record_store

Maybe try deleting the entire session not just the auth_token. I'm using same Devise setup above with the exception of devise_ldap_authenticator. Rails 4

# app/controllers/sessions_controller.rb class SessionsController < ApplicationController def destroy session.delete(:user_id) end end

Then in the view

# To log out <%= link_to "Log Out", destroy_user_session_path, :method => 'delete'%>

In my gemfile i'm using active-record session-store:

gem 'activerecord-session_store', github: 'rails/activerecord-session_store'

And in an initializer

Rails.application.config.session_store :active_record_store