在设备上注销不执行任何操作

Log Out on devise does nothing

我正在建立一个博客,我的注册工作正常,权限设置也很完美,但我无法注销用户..

这是我注销时在控制台中看到的内容:

Started DELETE "/users/sign_out" for 127.0.0.1 at 2015-07-16 14:41:07 -0500
Processing by Devise::SessionsController#destroy as HTML
  User Load (0.1ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ?  ORDER BY "users"."id" ASC LIMIT 1  [["id", 1]]
Can't verify CSRF token authenticity
   (0.0ms)  begin transaction
   (0.1ms)  commit transaction
Redirected to http://localhost:3000/
Completed 302 Found in 4ms (ActiveRecord: 0.2ms)

这是我的应用程序 erb 文件的样子:

<% if user_signed_in? %>            
    <div class="buttons">
        <button class="button"><%= link_to "New Post", new_post_path %></button>
        <button class="button"><%= link_to "Log Out", destroy_user_session_path, :method => :delete %></button>
    </div>
<% end %>

我在初始值设定项 devise.rb 文件

上有库存设置
 # The default HTTP method used to sign out a resource. Default is :delete.
  config.sign_out_via = :delete

但出于某种原因,当我按下注销按钮时,我没有注销。

这是我的 routs.rb(添加了 "devise_for :users do" 代码以使其正常工作):

Rails.application.routes.draw do
  devise_for :users do
  get '/users/sign_out' => 'devise/sessions#destroy'
end
  resources :posts do
  resources :comments
  end

  root "posts#index"

  get '/about', to: 'pages#about'

end

Haaalp....谢谢。

kb

在你的 layouts/application.html.erb 添加

<head>
  <%= csrf_meta_tags %>
</head>

您只能尝试以下行:

devise_for :users

而不是这些行

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

问题是请求没有发送 CSRF 令牌。查看服务器日志第4行:

Can't verify CSRF token authenticity

<%= csrf_meta_tag %> 放入您的页面应该有效。