Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
41
Help us understand the problem. What is going on with this article?
@colorrabbit

[Rails 4.x] Devise で Sign Out が Routing Error になる際の対応。(method の delete が get になる場合)

More than 5 years have passed since last update.

Rails4でのユーザー認証に、Deviseを使用しています。
Deviseでサインアウトする際に、Routing Errorが発生しました。

問題

routingでは以下の様になっています。

destroy_user_session DELETE     /users/sign_out(.:format)                         devise/sessions#destroy

viewは以下の感じです。

header.html.erb
<%= link_to "ログアウト", destroy_user_session_path, method: :delete, :class => 'navbar-link'  %> 

対応

delete が動かないので、get
以下を config/routes.rb に追記。

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

こうすると、routingが新しく足されて、/users/sign_outを上書きする形になります。

users_sign_out GET        /users/sign_out(.:format)                         devise/sessions#destroy

viewは書き換えても変えなくてもいいですが、一応変えます。

header.html.erb
<%= link_to "ログアウト", user_sign_out_path, method: :delete, :class => 'navbar-link'  %> 

原因

はっきりわかっていませんが、Herokuアプリはdeleteに対応していないとか。。。

参考

41
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
colorrabbit
creator.

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
41
Help us understand the problem. What is going on with this article?