0
0

More than 3 years have passed since last update.

Deviseのログイン・ログアウト後に転送するURLを変更する

Last updated at Posted at 2021-02-13

以下のように after_sign_in_path_forafter_sign_out_path_for をオーバーライドします。
調べてるとapplicationController に追加するという記事ばかりで、複数のアカウントを扱う場合に制御しにくいなと(UserとAdminとか)。
SessionControllerに記述してあげましょう。
stored_location_for を書いておくと、フレンドリーフォワーディング(ログイン画面に転送されるまえにリクエストしたページへリダイレクト)にも対応します。

class Hoge::SessionsController < Devise::SessionsController

  # 以下を追加
  def after_sign_in_path_for(resource_or_scope)
    stored_location_for(resource_or_scope) || customized_root_path
  end

  def after_sign_out_path_for(resource)
    new_hoge_session_path
  end
end

参考

ソースのコメントに Method used by sessions controller って書いてますな。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0