1

所以这似乎是一个非常普遍的问题。我已经梳理了 github 和 Stackoverflow 上的问题跟踪器,但仍然没有找到解决方案 - 除了更改config.sign_out_via = :deleteconfig.sign_out_via = :get- 这显然是非常糟糕的做法。

我的问题是,无论我尝试什么,客户端都会发送get请求而不是规定的deleteor post

在我看来
<%= link_to "sign out", destroy_user_session_path, :method => :delete %>

耙路线给出

Anchor$ rake routes
                  Prefix Verb   URI Pattern                                   Controller#Action
                    root GET    /                                             home#index
        new_user_session GET    /login(.:format)                              devise/sessions#new
            user_session POST   /login(.:format)                              devise/sessions#create
    destroy_user_session DELETE /logout(.:format)                             devise/sessions#destroy
           user_password POST   /password(.:format)                           devise/passwords#create
       new_user_password GET    /password/new(.:format)                       devise/passwords#new
      edit_user_password GET    /password/edit(.:format)                      devise/passwords#edit
                         PATCH  /password(.:format)                           devise/passwords#update
                         PUT    /password(.:format)                           devise/passwords#update
cancel_user_registration GET    /cancel(.:format)                             devise/registrations#cancel
       user_registration POST   /                                             devise/registrations#create
   new_user_registration GET    /sign_up(.:format)                            devise/registrations#new
  edit_user_registration GET    /edit(.:format)                               devise/registrations#edit
                         PATCH  /                                             devise/registrations#update
                         PUT    /                                             devise/registrations#update
                         DELETE /                                             devise/registrations#destroy
         user_activities GET    /users/:user_id/activities(.:format)          activities#index
                         POST   /users/:user_id/activities(.:format)          activities#create
       new_user_activity GET    /users/:user_id/activities/new(.:format)      activities#new
      edit_user_activity GET    /users/:user_id/activities/:id/edit(.:format) activities#edit
           user_activity GET    /users/:user_id/activities/:id(.:format)      activities#show
                         PATCH  /users/:user_id/activities/:id(.:format)      activities#update
                         PUT    /users/:user_id/activities/:id(.:format)      activities#update
                         DELETE /users/:user_id/activities/:id(.:format)      activities#destroy
                   users GET    /users(.:format)                              users#index
                         POST   /users(.:format)                              users#create
                new_user GET    /users/new(.:format)                          users#new
               edit_user GET    /users/:id/edit(.:format)                     users#edit
                    user GET    /users/:id(.:format)                          users#show
                         PATCH  /users/:id(.:format)                          users#update
                         PUT    /users/:id(.:format)                          users#update
                         DELETE /users/:id(.:format)                          users#destroy

路线.rb

root :to => "home#index"
  devise_for :users

  resources :users do
    resources :activities
  end

js清单

//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require turbolinks
//= require_tree .

application.html.erb 包含适当<%= javascript_include_tag "application" %>的包含 ujs 和呈现的标题包括:

<script src="/assets/jquery.js?body=1">
<script src="/assets/jquery_ujs.js?body=1">

我有一种感觉,它可能与 Turbolinks 有关,所以我尝试了多种变体data-no-turbolink,但没有雪茄。无论如何,客户端总是发送Started GET "/users/sign_out"哪个保持路由到UsersController#show。

任何见解都会有所帮助!

4

2 回答 2

0

在你看来试试这个

<a data-method="delete" href="<%= destroy_user_session_path %>">Logout</a>
于 2013-11-03T06:35:24.520 回答
0

我也有同样的问题:(现在在 Rails 4 中,我至少现在能做的就是路由

get '/users/sign_out' => 'devise/sessions#destroy'

*但是这种方法容易受到 CSRF 攻击

于 2013-12-13T07:34:44.127 回答