设计注销链接不起作用

时间:2014-01-17 08:04:36

标签: ruby-on-rails devise

为什么点击链接= link_to 'Logout', destroy_user_session_path, method: :deleteGET发送/users/sign_out请求并show view呈现UsersController?我的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路由输出为:

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

2 个答案:

答案 0 :(得分:2)

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

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

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

答案 1 :(得分:0)

应该适合你。

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