繁体   English   中英

设计注销链接不起作用

[英]Devise logout link doesn't work

为什么单击link = link_to 'Logout', destroy_user_session_path, method: :delete make GET请求到/users/sign_out并呈现UsersController show view 我的routes.rb是:

devise_for :users

  resources :users, only: [:show] do
    member do
      get 'profile'
      get 'purchases'
      get 'mailing'
    end
  end

/config/initializers/devise.rb包含config.sign_out_via = :delete ,rake routes输出为:

new_user_session GET    /users/sign_in(.:format)               devise/sessions#new
               user_session POST   /users/sign_in(.:format)               devise/sessions#create
       destroy_user_session DELETE /users/sign_out(.:format)              devise/sessions#destroy
              user_password POST   /users/password(.:format)              devise/passwords#create
          new_user_password GET    /users/password/new(.:format)          devise/passwords#new
         edit_user_password GET    /users/password/edit(.:format)         devise/passwords#edit
                            PATCH  /users/password(.:format)              devise/passwords#update
                            PUT    /users/password(.:format)              devise/passwords#update
   cancel_user_registration GET    /users/cancel(.:format)                devise/registrations#cancel
          user_registration POST   /users(.:format)                       devise/registrations#create
      new_user_registration GET    /users/sign_up(.:format)               devise/registrations#new
 edit_user_registration GET    /users/edit(.:format)                  devise/registrations#edit
                        PATCH  /users(.:format)                       devise/registrations#update
                        PUT    /users(.:format)                       devise/registrations#update
                        DELETE /users(.:format)                       devise/registrations#destroy
           profile_user GET    /users/:id/profile(.:format)           users#profile
         purchases_user GET    /users/:id/purchases(.:format)         users#purchases
           mailing_user GET    /users/:id/mailing(.:format)           users#mailing
                   user GET    /users/:id(.:format)                   users#show

为您的注销链接生成的html如下:

<a rel="nofollow" href="/users/sign_out" data-method="delete"></a>

这只有在正确加载js文件时才有效(我认为它需要jquery_ujs)否则它默认为GET请求。

它应该适合你。

<%= link_to "Sign out", destroy_user_session_path, :method => :delete %>

暂无
暂无

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

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