简体   繁体   English

Rails Devise Gem“ Sign_Out”无法退出

[英]Rails Devise Gem “Sign_Out” Fails to sign out

Error Message 错误信息

Rails Server
Processing by Devise::SessionsController#destroy as HTML
  User Load (0.5ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1      ORDER BY "users"."id" ASC LIMIT 1  [["id", 1]]
Can't verify CSRF token authenticity
   (0.4ms)  BEGIN
   (0.1ms)  COMMIT

I read this article thoroughly, my question is not a repeat because I researched! 我仔细阅读了这篇文章 ,我的问题不再重复了,因为我进行了研究!

I tried Cramheads suggestion: Added this to routes.rb 我尝试了Cramheads建议:将其 添加到routes.rb

devise_for :users do
  get '/users/sign_out' => 'devise/sessions#destroy'
end

I tried itkevins suggestion: changed devise.rb's default from 我尝试过itkevins建议: 将devise.rb的默认值从

config.sign_out_via = :delete
    to
config.sign_out_via = :get

this resulted in a routing error: 这导致路由错误:

uninitialized constant UsersController

I tried Rickys suggestion: changed devise.rb 我尝试 了Rickys的 建议: 更改了devise.rb

config.sign_out_via_get_becuase_of = :ie

this resulted in a method error: 这导致方法错误:

undefined method `sign_out_via_get_because_of=' for Devise:Module           (NoMethodError)

I tried Olives suggestion: adjusted the code slightly 我尝试了Olives建议: 稍微调整了代码

link_to :logout, destroy_user_session_path, :method => :delete 
    replacing 
link_to "Sign out", destroy_user_session_path, :method => :delete

I tried Victor Martins suggestion: Already had this in application.js 我尝试了Victor Martins的建议: application.js中已经有此选项

//= require jquery
//= require jquery_ujs

I tried Rezas suggestion: In routes.rb 我尝试了Rezas的建议: 在routes.rb中

devise_for :users

devise_scope :user do  
   get '/users/sign_out' => 'devise/sessions#destroy'     
end

I followed DuyKhoas suggestion as well: I included javascript 我也遵循DuyKhoas的建议: 我加入了javascript

<%= javascript_include_tag(:application) %>

I already had this so this wasn't helpful either. 我已经有了这个,所以这也没有帮助。

All the other suggestions were repeats of the already suggested fixes. 所有其他建议都是已建议的修复程序的重复。

HELP PLEASE! 请帮助! tT T

You can look at the Github Repo here . 您可以在这里查看Github回购

undefined method `sign_out_via_get_because_of=' for Devise:Module Devise:Module的未定义方法`sign_out_via_get_because_of ='
(NoMethodError) (NoMethodError)

There is no sign_out_via_get_because_of helper for devise. 没有sign_out_via_get_because_of设计助手。 There is only sign_out_via 只有sign_out_via

uninitialized constant UsersController 未初始化的常量UsersController

You don't have users_controller.rb under app/controllers , so is the error. 您在app/controllers下没有users_controller.rb ,因此错误也是如此。

#app/controllers/users_controller.rb

class UsersController < ApplicationController
end

For "sign_out_via" what exactly should I type? 对于“ sign_out_via”,我应该输入什么?

It depends on the method parameter in your link_to . 这取决于link_tomethod参数。 If it is :method => :delete then config.sign_out_via = :delete else config.sign_out_via = :get . 如果是:method => :deleteconfig.sign_out_via = :delete否则config.sign_out_via = :get

By convention should I run Rails g controller User or Rails g controller Users? 按照约定,我应该运行Rails g控制器用户还是Rails g控制器用户?

You should run rails g controller Users 您应该运行rails g controller Users

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

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